Skip to content

Commit bcd8b4a

Browse files
committed
[VPlan] CSE bugfix: consider Cmp Predicate
1 parent 8ab5fc6 commit bcd8b4a

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,8 @@ class VPIRFlags {
792792
}
793793

794794
CmpInst::Predicate getPredicate() const {
795-
assert(OpType == OperationType::Cmp &&
796-
"recipe doesn't have a compare predicate");
795+
if (OpType != OperationType::Cmp)
796+
return CmpInst::BAD_ICMP_PREDICATE;
797797
return CmpPredicate;
798798
}
799799

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,9 +1809,11 @@ struct VPCSEDenseMapInfo : public DenseMapInfo<VPSingleDefRecipe *> {
18091809
Def->getVPDefID(), getOpcodeOrIntrinsicID(Def),
18101810
TypeInfo.inferScalarType(Def), vputils::isSingleScalar(Def),
18111811
hash_combine_range(Def->operands()));
1812-
return isa<VPReplicateRecipe>(Def)
1813-
? hash_combine(Result, Def->getUnderlyingInstr())
1814-
: Result;
1812+
if (isa<VPReplicateRecipe>(Def))
1813+
return hash_combine(Result, Def->getUnderlyingInstr());
1814+
if (auto *RFlags = dyn_cast<VPRecipeWithIRFlags>(Def))
1815+
return hash_combine(Result, RFlags->getPredicate());
1816+
return Result;
18151817
}
18161818

18171819
/// Check equality of underlying data of \p L and \p R.
@@ -1827,6 +1829,9 @@ struct VPCSEDenseMapInfo : public DenseMapInfo<VPSingleDefRecipe *> {
18271829
equal(L->operands(), R->operands());
18281830
if (Result && isa<VPReplicateRecipe>(L))
18291831
Result = L->getUnderlyingInstr() == R->getUnderlyingInstr();
1832+
if (Result && isa<VPRecipeWithIRFlags>(L))
1833+
Result = cast<VPRecipeWithIRFlags>(L)->getPredicate() ==
1834+
cast<VPRecipeWithIRFlags>(R)->getPredicate();
18301835
assert((!Result || getHashValue(L) == getHashValue(R)) &&
18311836
"Divergent hashes of equal values");
18321837
return Result;

llvm/test/Transforms/LoopVectorize/single-value-blend-phis.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ define void @single_incoming_phi_with_blend_mask(i64 %a, i64 %b) {
101101
; CHECK-NEXT: [[TMP3:%.*]] = icmp ugt <2 x i64> [[VEC_IND]], [[BROADCAST_SPLAT]]
102102
; CHECK-NEXT: [[TMP4:%.*]] = getelementptr [32 x i16], ptr @src, i16 0, i16 [[TMP1]]
103103
; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <2 x i16>, ptr [[TMP4]], align 1
104-
; CHECK-NEXT: [[TMP7:%.*]] = select <2 x i1> [[TMP3]], <2 x i1> [[TMP3]], <2 x i1> zeroinitializer
104+
; CHECK-NEXT: [[TMP6:%.*]] = icmp sle <2 x i64> [[VEC_IND]], [[BROADCAST_SPLAT]]
105+
; CHECK-NEXT: [[TMP7:%.*]] = select <2 x i1> [[TMP3]], <2 x i1> [[TMP6]], <2 x i1> zeroinitializer
105106
; CHECK-NEXT: [[PREDPHI:%.*]] = select <2 x i1> [[TMP7]], <2 x i16> [[WIDE_LOAD]], <2 x i16> splat (i16 1)
106107
; CHECK-NEXT: [[PREDPHI1:%.*]] = select <2 x i1> [[TMP3]], <2 x i16> [[PREDPHI]], <2 x i16> zeroinitializer
107108
; CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds [32 x i16], ptr @dst, i16 0, i64 [[INDEX]]
@@ -285,7 +286,8 @@ define void @single_incoming_needs_predication(i64 %a, i64 %b) {
285286
; CHECK-NEXT: br label [[PRED_LOAD_CONTINUE2]]
286287
; CHECK: pred.load.continue2:
287288
; CHECK-NEXT: [[TMP14:%.*]] = phi <2 x i16> [ [[TMP8]], [[PRED_LOAD_CONTINUE]] ], [ [[TMP13]], [[PRED_LOAD_IF1]] ]
288-
; CHECK-NEXT: [[TMP16:%.*]] = select <2 x i1> [[TMP2]], <2 x i1> [[TMP2]], <2 x i1> zeroinitializer
289+
; CHECK-NEXT: [[TMP15:%.*]] = icmp sle <2 x i64> [[VEC_IND]], [[BROADCAST_SPLAT]]
290+
; CHECK-NEXT: [[TMP16:%.*]] = select <2 x i1> [[TMP2]], <2 x i1> [[TMP15]], <2 x i1> zeroinitializer
289291
; CHECK-NEXT: [[PREDPHI:%.*]] = select <2 x i1> [[TMP16]], <2 x i16> [[TMP14]], <2 x i16> splat (i16 1)
290292
; CHECK-NEXT: [[PREDPHI3:%.*]] = select <2 x i1> [[TMP2]], <2 x i16> [[PREDPHI]], <2 x i16> zeroinitializer
291293
; CHECK-NEXT: [[TMP18:%.*]] = getelementptr inbounds [32 x i16], ptr @dst, i16 0, i64 [[INDEX]]

0 commit comments

Comments
 (0)