Skip to content

[ValueTracking] Handle more integer intrinsics in propagatesPoison #82749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7194,6 +7194,21 @@ bool llvm::propagatesPoison(const Use &PoisonOp) {
// corresponding lanes are poison.
return true;
case Intrinsic::ctpop:
case Intrinsic::ctlz:
case Intrinsic::cttz:
case Intrinsic::abs:
case Intrinsic::smax:
case Intrinsic::smin:
case Intrinsic::umax:
case Intrinsic::umin:
case Intrinsic::bitreverse:
case Intrinsic::bswap:
case Intrinsic::sadd_sat:
case Intrinsic::ssub_sat:
case Intrinsic::sshl_sat:
case Intrinsic::uadd_sat:
case Intrinsic::usub_sat:
case Intrinsic::ushl_sat:
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Analysis/ScalarEvolution/exit-count-select-safe.ll
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ define i32 @logical_or_3ops_redundant_uminseq_operand(i32 %n, i32 %m, i32 %k) {
; CHECK-NEXT: %umin = call i32 @llvm.umin.i32(i32 %n, i32 %m)
; CHECK-NEXT: --> (%n umin %m) U: full-set S: full-set Exits: (%n umin %m) LoopDispositions: { %loop: Invariant }
; CHECK-NEXT: %cond_p3 = select i1 %cond_p0, i1 true, i1 %cond_p1
; CHECK-NEXT: --> (true + ((true + %cond_p0) umin_seq (true + %cond_p1))) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
; CHECK-NEXT: --> (true + ((true + %cond_p0) umin (true + %cond_p1))) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
; CHECK-NEXT: %cond = select i1 %cond_p3, i1 true, i1 %cond_p2
; CHECK-NEXT: --> (true + ((true + %cond_p0) umin_seq (true + %cond_p1) umin_seq (true + %cond_p2))) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
; CHECK-NEXT: --> (true + (((true + %cond_p0) umin (true + %cond_p1)) umin_seq (true + %cond_p2))) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
; CHECK-NEXT: Determining loop execution counts for: @logical_or_3ops_redundant_uminseq_operand
; CHECK-NEXT: Loop %loop: backedge-taken count is ((%n umin %m) umin_seq %k)
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is -1
Expand Down
59 changes: 23 additions & 36 deletions llvm/unittests/Analysis/ValueTrackingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,42 +824,7 @@ TEST_F(ValueTrackingTest, ComputeNumSignBits_Shuffle_Pointers) {
TEST(ValueTracking, propagatesPoison) {
std::string AsmHead =
"declare i32 @g(i32)\n"
"declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)\n"
"declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)\n"
"declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)\n"
"declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)\n"
"declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)\n"
"declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)\n"
"declare float @llvm.sqrt.f32(float)\n"
"declare float @llvm.powi.f32.i32(float, i32)\n"
"declare float @llvm.sin.f32(float)\n"
"declare float @llvm.cos.f32(float)\n"
"declare float @llvm.pow.f32(float, float)\n"
"declare float @llvm.exp.f32(float)\n"
"declare float @llvm.exp2.f32(float)\n"
"declare float @llvm.log.f32(float)\n"
"declare float @llvm.log10.f32(float)\n"
"declare float @llvm.log2.f32(float)\n"
"declare float @llvm.fma.f32(float, float, float)\n"
"declare float @llvm.fabs.f32(float)\n"
"declare float @llvm.minnum.f32(float, float)\n"
"declare float @llvm.maxnum.f32(float, float)\n"
"declare float @llvm.minimum.f32(float, float)\n"
"declare float @llvm.maximum.f32(float, float)\n"
"declare float @llvm.copysign.f32(float, float)\n"
"declare float @llvm.floor.f32(float)\n"
"declare float @llvm.ceil.f32(float)\n"
"declare float @llvm.trunc.f32(float)\n"
"declare float @llvm.rint.f32(float)\n"
"declare float @llvm.nearbyint.f32(float)\n"
"declare float @llvm.round.f32(float)\n"
"declare float @llvm.roundeven.f32(float)\n"
"declare i32 @llvm.lround.f32(float)\n"
"declare i64 @llvm.llround.f32(float)\n"
"declare i32 @llvm.lrint.f32(float)\n"
"declare i64 @llvm.llrint.f32(float)\n"
"declare float @llvm.fmuladd.f32(float, float, float)\n"
"define void @f(i32 %x, i32 %y, float %fx, float %fy, "
"define void @f(i32 %x, i32 %y, i32 %shamt, float %fx, float %fy, "
"i1 %cond, ptr %p) {\n";
std::string AsmTail = " ret void\n}";
// (propagates poison?, IR instruction)
Expand Down Expand Up @@ -912,6 +877,28 @@ TEST(ValueTracking, propagatesPoison) {
{true, "call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %x, i32 %y)", 0},
{true, "call {i32, i1} @llvm.usub.with.overflow.i32(i32 %x, i32 %y)", 0},
{true, "call {i32, i1} @llvm.umul.with.overflow.i32(i32 %x, i32 %y)", 0},
{true, "call i32 @llvm.sadd.sat.i32(i32 %x, i32 %y)", 0},
{true, "call i32 @llvm.ssub.sat.i32(i32 %x, i32 %y)", 0},
{true, "call i32 @llvm.sshl.sat.i32(i32 %x, i32 %y)", 0},
{true, "call i32 @llvm.uadd.sat.i32(i32 %x, i32 %y)", 0},
{true, "call i32 @llvm.usub.sat.i32(i32 %x, i32 %y)", 0},
{true, "call i32 @llvm.ushl.sat.i32(i32 %x, i32 %y)", 0},
{true, "call i32 @llvm.ctpop.i32(i32 %x)", 0},
{true, "call i32 @llvm.ctlz.i32(i32 %x, i1 true)", 0},
{true, "call i32 @llvm.cttz.i32(i32 %x, i1 true)", 0},
{true, "call i32 @llvm.abs.i32(i32 %x, i1 true)", 0},
{true, "call i32 @llvm.smax.i32(i32 %x, i32 %y)", 0},
{true, "call i32 @llvm.smin.i32(i32 %x, i32 %y)", 0},
{true, "call i32 @llvm.umax.i32(i32 %x, i32 %y)", 0},
{true, "call i32 @llvm.umin.i32(i32 %x, i32 %y)", 0},
{true, "call i32 @llvm.bitreverse.i32(i32 %x)", 0},
{true, "call i32 @llvm.bswap.i32(i32 %x)", 0},
{false, "call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 %shamt)", 0},
{false, "call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 %shamt)", 1},
{false, "call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 %shamt)", 2},
{false, "call i32 @llvm.fshr.i32(i32 %x, i32 %y, i32 %shamt)", 0},
{false, "call i32 @llvm.fshr.i32(i32 %x, i32 %y, i32 %shamt)", 1},
{false, "call i32 @llvm.fshr.i32(i32 %x, i32 %y, i32 %shamt)", 2},
{false, "call float @llvm.sqrt.f32(float %fx)", 0},
{false, "call float @llvm.powi.f32.i32(float %fx, i32 %x)", 0},
{false, "call float @llvm.sin.f32(float %fx)", 0},
Expand Down