[llvm] 6c03178 - [ConstantFold] Remove another incorrect icmp of gep fold

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 4 07:08:19 PST 2022


Author: Nikita Popov
Date: 2022-01-04T16:08:09+01:00
New Revision: 6c031780aa2c08996d1351de5e7541c75d6645c5

URL: https://github.com/llvm/llvm-project/commit/6c031780aa2c08996d1351de5e7541c75d6645c5
DIFF: https://github.com/llvm/llvm-project/commit/6c031780aa2c08996d1351de5e7541c75d6645c5.diff

LOG: [ConstantFold] Remove another incorrect icmp of gep fold

This folded (null + X) == g to false, but of course this is
incorrect if X == g.

Possibly this got confused with the null == g case, which is
already handled elsewhere.

Added: 
    

Modified: 
    llvm/lib/IR/ConstantFold.cpp
    llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 66e3a75833e2..0d76dd732d61 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -1541,12 +1541,7 @@ static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2,
             return ICmpInst::ICMP_UGT;
         }
       } else if (const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
-        if (isa<ConstantPointerNull>(CE1Op0)) {
-          // If its not weak linkage, the GVal must have a non-zero address
-          // so the result is less-than
-          if (!GV2->hasExternalWeakLinkage())
-            return ICmpInst::ICMP_ULT;
-        } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
+        if (const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
           if (GV != GV2) {
             if (CE1GEP->hasAllZeroIndices())
               return areGlobalsPotentiallyEqual(GV, GV2);

diff  --git a/llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll b/llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll
index cdf6be0e5243..aeb6ab4e504f 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll
@@ -168,7 +168,7 @@ define i1 @null_gep_ugt_null_constant_int() {
 
 define i1 @null_gep_ne_global() {
 ; CHECK-LABEL: @null_gep_ne_global(
-; CHECK-NEXT:    ret i1 true
+; CHECK-NEXT:    ret i1 icmp ne (i8* getelementptr (i8, i8* null, i64 ptrtoint (i8* @g3 to i64)), i8* @g3)
 ;
   %gep = getelementptr i8, i8* null, i64 ptrtoint (i8* @g3 to i64)
   %cmp = icmp ne i8* %gep, @g3
@@ -177,7 +177,7 @@ define i1 @null_gep_ne_global() {
 
 define i1 @null_gep_ult_global() {
 ; CHECK-LABEL: @null_gep_ult_global(
-; CHECK-NEXT:    ret i1 true
+; CHECK-NEXT:    ret i1 icmp ult (i8* getelementptr (i8, i8* null, i64 ptrtoint (i8* @g3 to i64)), i8* @g3)
 ;
   %gep = getelementptr i8, i8* null, i64 ptrtoint (i8* @g3 to i64)
   %cmp = icmp ult i8* %gep, @g3


        


More information about the llvm-commits mailing list