Skip to content

Commit 9a8b6ee

Browse files
committed
Bail if return_type != elt_type
1 parent 41200f3 commit 9a8b6ee

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -653,16 +653,16 @@ void GISelValueTracking::computeKnownBitsImpl(Register R, KnownBits &Known,
653653
if (VecVT.isScalableVector())
654654
break;
655655

656-
Known.Zero.setAllBits();
657-
Known.One.setAllBits();
658-
659656
const unsigned EltBitWidth = VecVT.getScalarSizeInBits();
660657
const unsigned NumSrcElts = VecVT.getNumElements();
658+
// A return type different from the vector's element type may lead to
659+
// issues with pattern selection. Bail out to avoid that.
660+
if (BitWidth > EltBitWidth) {
661+
break;
662+
}
661663

662-
// If BitWidth > EltBitWidth the value is anyext:ed. So we do not know
663-
// anything about the extended bits.
664-
if (BitWidth > EltBitWidth)
665-
Known = Known.trunc(EltBitWidth);
664+
Known.Zero.setAllBits();
665+
Known.One.setAllBits();
666666

667667
// If we know the element index, just demand that vector element, else for
668668
// an unknown element index, ignore DemandedElts and demand them all.
@@ -673,10 +673,7 @@ void GISelValueTracking::computeKnownBitsImpl(Register R, KnownBits &Known,
673673

674674
computeKnownBitsImpl(InVec, Known2, DemandedSrcElts, Depth + 1);
675675
Known = Known.intersectWith(Known2);
676-
677-
if (BitWidth > EltBitWidth)
678-
Known = Known.anyext(BitWidth);
679-
676+
680677
break;
681678
}
682679
case TargetOpcode::G_SHUFFLE_VECTOR: {

llvm/test/CodeGen/AArch64/GlobalISel/knownbits-extract-vector.mir

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,19 @@ body: |
115115
%1:_(s16) = G_EXTRACT_VECTOR_ELT %sext0, %idx
116116
...
117117
---
118+
# Verifies known bit computation bails if return type differs from vector
119+
# element type. Without bailing, the 8 lowest bits of %4 would be known.
120+
name: bail_on_different_return_type
121+
body: |
122+
bb.0:
123+
; CHECK-LABEL: name: @bail_on_different_return_type
124+
; CHECK-NEXT: %0:_ KnownBits:00000011 SignBits:6
125+
; CHECK-NEXT: %1:_ KnownBits:00001010 SignBits:4
126+
; CHECK-NEXT: %2:_ KnownBits:0000?01? SignBits:4
127+
; CHECK-NEXT: %idx:_ KnownBits:0000000000000000000000000000000000000000000000000000000000000001 SignBits:63
128+
; CHECK-NEXT: %4:_ KnownBits:???????????????? SignBits:1
129+
%0:_(s8) = G_CONSTANT i8 3
130+
%1:_(s8) = G_CONSTANT i8 10
131+
%2:_(<2 x s8>) = G_BUILD_VECTOR %0, %1
132+
%idx:_(s64) = G_CONSTANT i64 1
133+
%3:_(s16) = G_EXTRACT_VECTOR_ELT %2, %idx

0 commit comments

Comments
 (0)