[llvm] r239217 - [CVP] Don't assume Constants of type i1 can be known to be true or false

David Majnemer david.majnemer at gmail.com
Fri Jun 5 21:56:52 PDT 2015


Author: majnemer
Date: Fri Jun  5 23:56:51 2015
New Revision: 239217

URL: http://llvm.org/viewvc/llvm-project?rev=239217&view=rev
Log:
[CVP] Don't assume Constants of type i1 can be known to be true or false

CVP wants to analyze the condition operand of a select along an edge.
It succeeds in getting back a Constant but not a ConstantInt.  Instead,
it gets a ConstantExpr.  It then assumes that the Constant must be equal
to false because it isn't equal to true.

Instead, perform an additional comparison.

This fixes PR23752.

Modified:
    llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
    llvm/trunk/test/Transforms/CorrelatedValuePropagation/select.ll

Modified: llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp?rev=239217&r1=239216&r2=239217&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp Fri Jun  5 23:56:51 2015
@@ -113,10 +113,11 @@ bool CorrelatedValuePropagation::process
 
       Value *Condition = SI->getCondition();
       if (!Condition->getType()->isVectorTy()) {
-        if (Constant *C = LVI->getConstantOnEdge(Condition, P->getIncomingBlock(i), BB, P)) {
-          if (C == ConstantInt::getTrue(Condition->getType())) {
+        if (Constant *C = LVI->getConstantOnEdge(
+                Condition, P->getIncomingBlock(i), BB, P)) {
+          if (C->isOneValue()) {
             V = SI->getTrueValue();
-          } else {
+          } else if (C->isZeroValue()) {
             V = SI->getFalseValue();
           }
           // Once LVI learns to handle vector types, we could also add support

Modified: llvm/trunk/test/Transforms/CorrelatedValuePropagation/select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CorrelatedValuePropagation/select.ll?rev=239217&r1=239216&r2=239217&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/CorrelatedValuePropagation/select.ll (original)
+++ llvm/trunk/test/Transforms/CorrelatedValuePropagation/select.ll Fri Jun  5 23:56:51 2015
@@ -51,3 +51,25 @@ else:
   ret i8 %b
 }
 
+ at c = global i32 0, align 4
+ at b = global i32 0, align 4
+
+; CHECK-LABEL: @PR23752(
+define i32 @PR23752() {
+entry:
+  br label %for.body
+
+for.body:
+  %phi = phi i32 [ 0, %entry ], [ %sel, %for.body ]
+  %sel = select i1 icmp sgt (i32* @b, i32* @c), i32 %phi, i32 1
+  %cmp = icmp ne i32 %sel, 1
+  br i1 %cmp, label %for.body, label %if.end
+
+; CHECK:      %[[sel:.*]] = select i1 icmp sgt (i32* @b, i32* @c), i32 0, i32 1
+; CHECK-NEXT: %[[cmp:.*]] = icmp ne i32 %[[sel]], 1
+; CHECK-NEXT: br i1 %[[cmp]]
+
+if.end:
+  ret i32 %sel
+; CHECK: ret i32 %[[sel]]
+}





More information about the llvm-commits mailing list