Skip to content

Commit 92ebaf5

Browse files
Minor change and tests added
1 parent 2c804af commit 92ebaf5

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,12 +1322,11 @@ static void computeKnownBitsFromOperator(const Operator *I,
13221322
isa<ScalableVectorType>(I->getType()))
13231323
break;
13241324

1325+
unsigned NumElts = DemandedElts.getBitWidth();
1326+
bool IsLE = Q.DL.isLittleEndian();
13251327
// Look through a cast from narrow vector elements to wider type.
13261328
// Examples: v4i32 -> v2i64, v3i8 -> v24
13271329
unsigned SubBitWidth = SrcVecTy->getScalarSizeInBits();
1328-
unsigned NumElts = DemandedElts.getBitWidth();
1329-
unsigned SubScale = BitWidth / SubBitWidth;
1330-
bool isLE = Q.DL.isLittleEndian();
13311330
if (BitWidth % SubBitWidth == 0) {
13321331
// Known bits are automatically intersected across demanded elements of a
13331332
// vector. So for example, if a bit is computed as known zero, it must be
@@ -1343,6 +1342,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
13431342
//
13441343
// The known bits of each sub-element are then inserted into place
13451344
// (dependent on endian) to form the full result of known bits.
1345+
unsigned SubScale = BitWidth / SubBitWidth;
13461346
APInt SubDemandedElts = APInt::getZero(NumElts * SubScale);
13471347
for (unsigned i = 0; i != NumElts; ++i) {
13481348
if (DemandedElts[i])
@@ -1353,12 +1353,13 @@ static void computeKnownBitsFromOperator(const Operator *I,
13531353
for (unsigned i = 0; i != SubScale; ++i) {
13541354
computeKnownBits(I->getOperand(0), SubDemandedElts.shl(i), KnownSrc,
13551355
Depth + 1, Q);
1356-
unsigned ShiftElt = isLE ? i : SubScale - 1 - i;
1356+
unsigned ShiftElt = IsLE ? i : SubScale - 1 - i;
13571357
Known.insertBits(KnownSrc, ShiftElt * SubBitWidth);
13581358
}
13591359
}
13601360

13611361
if (SubBitWidth % BitWidth == 0) {
1362+
unsigned SubScale = SubBitWidth / BitWidth;
13621363
KnownBits KnownSrc(SubBitWidth);
13631364
APInt SubDemandedElts =
13641365
APIntOps::ScaleBitMask(DemandedElts, NumElts / SubScale);
@@ -1369,7 +1370,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
13691370
Known.One.setAllBits();
13701371
for (unsigned i = 0; i != SubScale; ++i) {
13711372
if (DemandedElts[i]) {
1372-
unsigned Shifts = isLE ? i : NumElts - 1 - i;
1373+
unsigned Shifts = IsLE ? i : NumElts - 1 - i;
13731374
unsigned Offset = (Shifts % SubScale) * BitWidth;
13741375
Known = Known.intersectWith(KnownSrc.extractBits(BitWidth, Offset));
13751376
if (Known.isUnknown())

llvm/test/Transforms/InstCombine/X86/x86-vector-shifts.ll

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3732,19 +3732,21 @@ define <4 x i64> @test_avx2_psrl_0() {
37323732
ret <4 x i64> %16
37333733
}
37343734

3735-
; FIXME: Failure to peek through bitcasts to ensure psllq shift amount is within bounds.
3736-
define <2 x i64> @PR125228(<2 x i64> %v, <2 x i64> %s) {
3737-
; CHECK-LABEL: @PR125228(
3735+
define <2 x i64> @pr125228(<2 x i64> %v, <2 x i64> %s) {
3736+
; CHECK-LABEL: @pr125228(
3737+
; CHECK-NEXT: entry:
37383738
; CHECK-NEXT: [[MASK:%.*]] = and <2 x i64> [[S:%.*]], splat (i64 63)
3739-
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x i64> [[MASK]], <2 x i64> poison, <2 x i32> zeroinitializer
3740-
; CHECK-NEXT: [[SLL0:%.*]] = shl <2 x i64> [[V:%.*]], [[TMP1]]
3739+
; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <2 x i64> [[MASK]], <2 x i64> poison, <2 x i32> zeroinitializer
3740+
; CHECK-NEXT: [[SLL0:%.*]] = shl <2 x i64> [[V:%.*]], [[TMP0]]
37413741
; CHECK-NEXT: [[CAST:%.*]] = bitcast <2 x i64> [[MASK]] to <16 x i8>
37423742
; CHECK-NEXT: [[PSRLDQ:%.*]] = shufflevector <16 x i8> [[CAST]], <16 x i8> poison, <16 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
37433743
; CHECK-NEXT: [[CAST3:%.*]] = bitcast <16 x i8> [[PSRLDQ]] to <2 x i64>
3744-
; CHECK-NEXT: [[SLL1:%.*]] = call <2 x i64> @llvm.x86.sse2.psll.q(<2 x i64> [[V]], <2 x i64> [[CAST3]])
3744+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x i64> [[CAST3]], <2 x i64> poison, <2 x i32> zeroinitializer
3745+
; CHECK-NEXT: [[SLL1:%.*]] = shl <2 x i64> [[V]], [[TMP1]]
37453746
; CHECK-NEXT: [[SHUFP_UNCASTED:%.*]] = shufflevector <2 x i64> [[SLL0]], <2 x i64> [[SLL1]], <2 x i32> <i32 0, i32 3>
37463747
; CHECK-NEXT: ret <2 x i64> [[SHUFP_UNCASTED]]
37473748
;
3749+
entry:
37483750
%mask = and <2 x i64> %s, splat (i64 63)
37493751
%sll0 = call <2 x i64> @llvm.x86.sse2.psll.q(<2 x i64> %v, <2 x i64> %mask)
37503752
%cast = bitcast <2 x i64> %mask to <16 x i8>

0 commit comments

Comments
 (0)