[llvm-commits] [llvm] r91587 - in /llvm/trunk: lib/VMCore/ConstantFold.cpp test/Transforms/InstCombine/constant-fold-compare.ll

Eli Friedman eli.friedman at gmail.com
Wed Dec 16 22:07:05 PST 2009


Author: efriedma
Date: Thu Dec 17 00:07:04 2009
New Revision: 91587

URL: http://llvm.org/viewvc/llvm-project?rev=91587&view=rev
Log:
Aggressively flip compare constant expressions where appropriate; constant
folding in particular expects null to be on the RHS.


Added:
    llvm/trunk/test/Transforms/InstCombine/constant-fold-compare.ll
Modified:
    llvm/trunk/lib/VMCore/ConstantFold.cpp

Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=91587&r1=91586&r2=91587&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Thu Dec 17 00:07:04 2009
@@ -1839,14 +1839,16 @@
       }
     }
 
-    if (!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) {
+    if ((!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) ||
+        (C1->isNullValue() && !C2->isNullValue())) {
       // If C2 is a constant expr and C1 isn't, flip them around and fold the
       // other way if possible.
+      // Also, if C1 is null and C2 isn't, flip them around.
       switch (pred) {
       case ICmpInst::ICMP_EQ:
       case ICmpInst::ICMP_NE:
         // No change of predicate required.
-        return ConstantFoldCompareInstruction(Context, pred, C2, C1);
+        return ConstantExpr::getICmp(pred, C2, C1);
 
       case ICmpInst::ICMP_ULT:
       case ICmpInst::ICMP_SLT:
@@ -1858,7 +1860,7 @@
       case ICmpInst::ICMP_SGE:
         // Change the predicate as necessary to swap the operands.
         pred = ICmpInst::getSwappedPredicate((ICmpInst::Predicate)pred);
-        return ConstantFoldCompareInstruction(Context, pred, C2, C1);
+        return ConstantExpr::getICmp(pred, C2, C1);
 
       default:  // These predicates cannot be flopped around.
         break;

Added: llvm/trunk/test/Transforms/InstCombine/constant-fold-compare.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/constant-fold-compare.ll?rev=91587&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/constant-fold-compare.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/constant-fold-compare.ll Thu Dec 17 00:07:04 2009
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
+
+define i32 @a() nounwind readnone {
+entry:
+  ret i32 zext (i1 icmp eq (i32 0, i32 ptrtoint (i32 ()* @a to i32)) to i32)
+}
+; CHECK: ret i32 0





More information about the llvm-commits mailing list