Skip to content

Commit

Permalink
[SLP]Fix minbitwidth emission and analysis for freeze instruction
Browse files Browse the repository at this point in the history
Need to add minbw emission and analysis for freeze instruction to fix
incorrect signedness propagation.

Fixes #112460
  • Loading branch information
alexey-bataev committed Oct 18, 2024
1 parent 65cf7af commit e56e9dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14953,6 +14953,12 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
return E->VectorizedValue;
}

if (Op->getType() != VecTy) {
assert((It != MinBWs.end() || getOperandEntry(E, 0)->isGather() ||
MinBWs.contains(getOperandEntry(E, 0))) &&
"Expected item in MinBWs.");
Op = Builder.CreateIntCast(Op, VecTy, GetOperandSignedness(0));
}
Value *V = Builder.CreateFreeze(Op);
V = FinalShuffle(V, E);

Expand Down Expand Up @@ -17095,6 +17101,8 @@ bool BoUpSLP::collectValuesToDemote(
return TryProcessInstruction(
BitWidth, {getOperandEntry(&E, 0), getOperandEntry(&E, 1)});
}
case Instruction::Freeze:
return TryProcessInstruction(BitWidth, getOperandEntry(&E, 0));
case Instruction::Shl: {
// If we are truncating the result of this SHL, and if it's a shift of an
// inrange amount, we can always perform a SHL in a smaller type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ define i32 @test(i1 %.b, i8 %conv18, i32 %k.promoted61) {
; CHECK-NEXT: [[TMP3:%.*]] = xor <4 x i1> [[TMP2]], <i1 true, i1 true, i1 true, i1 true>
; CHECK-NEXT: [[TMP4:%.*]] = zext <4 x i1> [[TMP3]] to <4 x i8>
; CHECK-NEXT: [[TMP5:%.*]] = icmp eq <4 x i8> [[TMP4]], zeroinitializer
; CHECK-NEXT: [[TMP6:%.*]] = freeze <4 x i1> [[TMP3]]
; CHECK-NEXT: [[TMP7:%.*]] = sext <4 x i1> [[TMP6]] to <4 x i8>
; CHECK-NEXT: [[TMP6:%.*]] = zext <4 x i1> [[TMP3]] to <4 x i8>
; CHECK-NEXT: [[TMP7:%.*]] = freeze <4 x i8> [[TMP6]]
; CHECK-NEXT: [[TMP8:%.*]] = insertelement <4 x i8> poison, i8 [[CONV18]], i32 0
; CHECK-NEXT: [[TMP9:%.*]] = shufflevector <4 x i8> [[TMP8]], <4 x i8> poison, <4 x i32> zeroinitializer
; CHECK-NEXT: [[TMP10:%.*]] = icmp ugt <4 x i8> [[TMP7]], [[TMP9]]
Expand Down

0 comments on commit e56e9dd

Please sign in to comment.