[llvm-commits] [llvm] r82361 - in /llvm/trunk: lib/VMCore/ConstantFold.cpp test/Assembler/ConstantExprFold.ll
Nick Lewycky
nicholas at mxc.ca
Sat Sep 19 21:27:06 PDT 2009
Author: nicholas
Date: Sat Sep 19 23:27:06 2009
New Revision: 82361
URL: http://llvm.org/viewvc/llvm-project?rev=82361&view=rev
Log:
Clean up the usage of evaluateICmpRelation's return value.
Add another line to the ConstantExprFold test to demonstrate the GEPs may not
wrap around in either the signed or unsigned senses.
Modified:
llvm/trunk/lib/VMCore/ConstantFold.cpp
llvm/trunk/test/Assembler/ConstantExprFold.ll
Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=82361&r1=82360&r2=82361&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Sat Sep 19 23:27:06 2009
@@ -1263,7 +1263,7 @@
else
// If its not weak linkage, the GVal must have a non-zero address
// so the result is greater-than
- return isSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
+ return isSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
} else if (isa<ConstantPointerNull>(CE1Op0)) {
// If we are indexing from a null pointer, check to see if we have any
// non-zero indices.
@@ -1567,64 +1567,57 @@
case ICmpInst::ICMP_EQ: // We know the constants are equal!
// If we know the constants are equal, we can decide the result of this
// computation precisely.
- Result = (pred == ICmpInst::ICMP_EQ ||
- pred == ICmpInst::ICMP_ULE ||
- pred == ICmpInst::ICMP_SLE ||
- pred == ICmpInst::ICMP_UGE ||
- pred == ICmpInst::ICMP_SGE);
+ Result = ICmpInst::isTrueWhenEqual((ICmpInst::Predicate)pred);
break;
case ICmpInst::ICMP_ULT:
- // If we know that C1 < C2, we can decide the result of this computation
- // precisely.
- Result = (pred == ICmpInst::ICMP_ULT ||
- pred == ICmpInst::ICMP_NE ||
- pred == ICmpInst::ICMP_ULE);
+ switch (pred) {
+ case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_NE: case ICmpInst::ICMP_ULE:
+ Result = 1; break;
+ case ICmpInst::ICMP_UGT: case ICmpInst::ICMP_EQ: case ICmpInst::ICMP_UGE:
+ Result = 0; break;
+ }
break;
case ICmpInst::ICMP_SLT:
- // If we know that C1 < C2, we can decide the result of this computation
- // precisely.
- Result = (pred == ICmpInst::ICMP_SLT ||
- pred == ICmpInst::ICMP_NE ||
- pred == ICmpInst::ICMP_SLE);
+ switch (pred) {
+ case ICmpInst::ICMP_SLT: case ICmpInst::ICMP_NE: case ICmpInst::ICMP_SLE:
+ Result = 1; break;
+ case ICmpInst::ICMP_SGT: case ICmpInst::ICMP_EQ: case ICmpInst::ICMP_SGE:
+ Result = 0; break;
+ }
break;
case ICmpInst::ICMP_UGT:
- // If we know that C1 > C2, we can decide the result of this computation
- // precisely.
- Result = (pred == ICmpInst::ICMP_UGT ||
- pred == ICmpInst::ICMP_NE ||
- pred == ICmpInst::ICMP_UGE);
+ switch (pred) {
+ case ICmpInst::ICMP_UGT: case ICmpInst::ICMP_NE: case ICmpInst::ICMP_UGE:
+ Result = 1; break;
+ case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_EQ: case ICmpInst::ICMP_ULE:
+ Result = 0; break;
+ }
break;
case ICmpInst::ICMP_SGT:
- // If we know that C1 > C2, we can decide the result of this computation
- // precisely.
- Result = (pred == ICmpInst::ICMP_SGT ||
- pred == ICmpInst::ICMP_NE ||
- pred == ICmpInst::ICMP_SGE);
+ switch (pred) {
+ case ICmpInst::ICMP_SGT: case ICmpInst::ICMP_NE: case ICmpInst::ICMP_SGE:
+ Result = 1; break;
+ case ICmpInst::ICMP_SLT: case ICmpInst::ICMP_EQ: case ICmpInst::ICMP_SLE:
+ Result = 0; break;
+ }
break;
case ICmpInst::ICMP_ULE:
- // If we know that C1 <= C2, we can only partially decide this relation.
if (pred == ICmpInst::ICMP_UGT) Result = 0;
- if (pred == ICmpInst::ICMP_ULT) Result = 1;
+ if (pred == ICmpInst::ICMP_ULT || pred == ICmpInst::ICMP_ULE) Result = 1;
break;
case ICmpInst::ICMP_SLE:
- // If we know that C1 <= C2, we can only partially decide this relation.
if (pred == ICmpInst::ICMP_SGT) Result = 0;
- if (pred == ICmpInst::ICMP_SLT) Result = 1;
+ if (pred == ICmpInst::ICMP_SLT || pred == ICmpInst::ICMP_SLE) Result = 1;
break;
-
case ICmpInst::ICMP_UGE:
- // If we know that C1 >= C2, we can only partially decide this relation.
if (pred == ICmpInst::ICMP_ULT) Result = 0;
- if (pred == ICmpInst::ICMP_UGT) Result = 1;
+ if (pred == ICmpInst::ICMP_UGT || pred == ICmpInst::ICMP_UGE) Result = 1;
break;
case ICmpInst::ICMP_SGE:
- // If we know that C1 >= C2, we can only partially decide this relation.
if (pred == ICmpInst::ICMP_SLT) Result = 0;
- if (pred == ICmpInst::ICMP_SGT) Result = 1;
+ if (pred == ICmpInst::ICMP_SGT || pred == ICmpInst::ICMP_SGE) Result = 1;
break;
-
case ICmpInst::ICMP_NE:
- // If we know that C1 != C2, we can only partially decide this relation.
if (pred == ICmpInst::ICMP_EQ) Result = 0;
if (pred == ICmpInst::ICMP_NE) Result = 1;
break;
Modified: llvm/trunk/test/Assembler/ConstantExprFold.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/ConstantExprFold.ll?rev=82361&r1=82360&r2=82361&view=diff
==============================================================================
--- llvm/trunk/test/Assembler/ConstantExprFold.ll (original)
+++ llvm/trunk/test/Assembler/ConstantExprFold.ll Sat Sep 19 23:27:06 2009
@@ -19,6 +19,7 @@
@B = external global %Ty
global i1 icmp slt (i64* @A, i64* getelementptr (i64* @A, i64 1)) ; true
+global i1 icmp ult (i64* @A, i64* getelementptr (i64* @A, i64 1)) ; true
global i1 icmp slt (i64* @A, i64* getelementptr (i64* @A, i64 0)) ; false
global i1 icmp slt (i32* getelementptr (%Ty* @B, i64 0, i32 0),
i32* getelementptr (%Ty* @B, i64 0, i32 1)) ; true
More information about the llvm-commits
mailing list