[llvm] 9ebeac6 - [ConstantRange][CVP] Make use of abs poison flag

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 30 14:06:24 PDT 2020


Author: Nikita Popov
Date: 2020-07-30T23:06:10+02:00
New Revision: 9ebeac678855a1bc2492a9630f0300518e2755dc

URL: https://github.com/llvm/llvm-project/commit/9ebeac678855a1bc2492a9630f0300518e2755dc
DIFF: https://github.com/llvm/llvm-project/commit/9ebeac678855a1bc2492a9630f0300518e2755dc.diff

LOG: [ConstantRange][CVP] Make use of abs poison flag

Pass the abs poison flag to the underlying ConstantRange
implementation, allowing CVP to simplify based on it.

Importantly, this recognizes that abs with poison flag is actually
non-negative...

Added: 
    

Modified: 
    llvm/lib/IR/ConstantRange.cpp
    llvm/test/Transforms/CorrelatedValuePropagation/minmaxabs.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index 6e0b5a0fc860..396c39b5b3a8 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -872,9 +872,12 @@ ConstantRange ConstantRange::intrinsic(Intrinsic::ID IntrinsicID,
     return Ops[0].smin(Ops[1]);
   case Intrinsic::smax:
     return Ops[0].smax(Ops[1]);
-  case Intrinsic::abs:
-    // TODO: Make use of poison flag.
-    return Ops[0].abs();
+  case Intrinsic::abs: {
+    const APInt *IntMinIsPoison = Ops[1].getSingleElement();
+    assert(IntMinIsPoison && "Must be known (immarg)");
+    assert(IntMinIsPoison->getBitWidth() == 1 && "Must be boolean");
+    return Ops[0].abs(IntMinIsPoison->getBoolValue());
+  }
   default:
     assert(!isIntrinsicSupported(IntrinsicID) && "Shouldn't be supported");
     llvm_unreachable("Unsupported intrinsic");

diff  --git a/llvm/test/Transforms/CorrelatedValuePropagation/minmaxabs.ll b/llvm/test/Transforms/CorrelatedValuePropagation/minmaxabs.ll
index ef5bf4d7c2a1..040bc8ae9016 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/minmaxabs.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/minmaxabs.ll
@@ -141,8 +141,7 @@ define void @test_abs3(i32 %x) {
 ; CHECK-NEXT:    [[A:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 true)
 ; CHECK-NEXT:    br label [[SPLIT:%.*]]
 ; CHECK:       split:
-; CHECK-NEXT:    [[C1:%.*]] = icmp sge i32 [[A]], 0
-; CHECK-NEXT:    call void @use(i1 [[C1]])
+; CHECK-NEXT:    call void @use(i1 true)
 ; CHECK-NEXT:    [[C2:%.*]] = icmp sgt i32 [[A]], 0
 ; CHECK-NEXT:    call void @use(i1 [[C2]])
 ; CHECK-NEXT:    ret void


        


More information about the llvm-commits mailing list