[llvm] 1bd11d3 - [ConstFold] Add additional icmp of gep of global tests (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 28 05:14:11 PST 2021


Author: Nikita Popov
Date: 2021-12-28T14:07:15+01:00
New Revision: 1bd11d34feecde09958669f6c507b9a10cc6b2ab

URL: https://github.com/llvm/llvm-project/commit/1bd11d34feecde09958669f6c507b9a10cc6b2ab
DIFF: https://github.com/llvm/llvm-project/commit/1bd11d34feecde09958669f6c507b9a10cc6b2ab.diff

LOG: [ConstFold] Add additional icmp of gep of global tests (NFC)

The fold is incorrect for the sgt case, as gep inbounds is allowed
to cross the sign boundary.

Added: 
    llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll

Modified: 
    

Removed: 
    llvm/test/Transforms/InstSimplify/ConstProp/icmp-null.ll


################################################################################
diff  --git a/llvm/test/Transforms/InstSimplify/ConstProp/icmp-null.ll b/llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll
similarity index 90%
rename from llvm/test/Transforms/InstSimplify/ConstProp/icmp-null.ll
rename to llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll
index 8698132b87f97..9e5a54a8a65c1 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/icmp-null.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll
@@ -215,3 +215,24 @@ define i1 @global_gep_sgt_global_neg_offset() {
   %cmp = icmp sgt [2 x i32]* %gep, @g
   ret i1 %cmp
 }
+
+define i1 @global_gep_ugt_global_gep() {
+; CHECK-LABEL: @global_gep_ugt_global_gep(
+; CHECK-NEXT:    ret i1 true
+;
+  %gep1 = getelementptr inbounds [2 x i32], [2 x i32]* @g, i64 0, i64 0
+  %gep2 = getelementptr inbounds [2 x i32], [2 x i32]* @g, i64 0, i64 1
+  %cmp = icmp ugt i32* %gep2, %gep1
+  ret i1 %cmp
+}
+
+; TODO: Should not fold due to signed comparison.
+define i1 @global_gep_sgt_global_gep() {
+; CHECK-LABEL: @global_gep_sgt_global_gep(
+; CHECK-NEXT:    ret i1 true
+;
+  %gep1 = getelementptr inbounds [2 x i32], [2 x i32]* @g, i64 0, i64 0
+  %gep2 = getelementptr inbounds [2 x i32], [2 x i32]* @g, i64 0, i64 1
+  %cmp = icmp sgt i32* %gep2, %gep1
+  ret i1 %cmp
+}


        


More information about the llvm-commits mailing list