Skip to content

Commit e56e9dd

Browse files
committed
[SLP]Fix minbitwidth emission and analysis for freeze instruction
Need to add minbw emission and analysis for freeze instruction to fix incorrect signedness propagation. Fixes llvm#112460
1 parent 65cf7af commit e56e9dd

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14953,6 +14953,12 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
1495314953
return E->VectorizedValue;
1495414954
}
1495514955

14956+
if (Op->getType() != VecTy) {
14957+
assert((It != MinBWs.end() || getOperandEntry(E, 0)->isGather() ||
14958+
MinBWs.contains(getOperandEntry(E, 0))) &&
14959+
"Expected item in MinBWs.");
14960+
Op = Builder.CreateIntCast(Op, VecTy, GetOperandSignedness(0));
14961+
}
1495614962
Value *V = Builder.CreateFreeze(Op);
1495714963
V = FinalShuffle(V, E);
1495814964

@@ -17095,6 +17101,8 @@ bool BoUpSLP::collectValuesToDemote(
1709517101
return TryProcessInstruction(
1709617102
BitWidth, {getOperandEntry(&E, 0), getOperandEntry(&E, 1)});
1709717103
}
17104+
case Instruction::Freeze:
17105+
return TryProcessInstruction(BitWidth, getOperandEntry(&E, 0));
1709817106
case Instruction::Shl: {
1709917107
// If we are truncating the result of this SHL, and if it's a shift of an
1710017108
// inrange amount, we can always perform a SHL in a smaller type.

llvm/test/Transforms/SLPVectorizer/freeze-signedness-missed.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ define i32 @test(i1 %.b, i8 %conv18, i32 %k.promoted61) {
99
; CHECK-NEXT: [[TMP3:%.*]] = xor <4 x i1> [[TMP2]], <i1 true, i1 true, i1 true, i1 true>
1010
; CHECK-NEXT: [[TMP4:%.*]] = zext <4 x i1> [[TMP3]] to <4 x i8>
1111
; CHECK-NEXT: [[TMP5:%.*]] = icmp eq <4 x i8> [[TMP4]], zeroinitializer
12-
; CHECK-NEXT: [[TMP6:%.*]] = freeze <4 x i1> [[TMP3]]
13-
; CHECK-NEXT: [[TMP7:%.*]] = sext <4 x i1> [[TMP6]] to <4 x i8>
12+
; CHECK-NEXT: [[TMP6:%.*]] = zext <4 x i1> [[TMP3]] to <4 x i8>
13+
; CHECK-NEXT: [[TMP7:%.*]] = freeze <4 x i8> [[TMP6]]
1414
; CHECK-NEXT: [[TMP8:%.*]] = insertelement <4 x i8> poison, i8 [[CONV18]], i32 0
1515
; CHECK-NEXT: [[TMP9:%.*]] = shufflevector <4 x i8> [[TMP8]], <4 x i8> poison, <4 x i32> zeroinitializer
1616
; CHECK-NEXT: [[TMP10:%.*]] = icmp ugt <4 x i8> [[TMP7]], [[TMP9]]

0 commit comments

Comments
 (0)