[llvm] aefab6f - [InstSimplify] Use weak symbol in test to show miscompile (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 4 03:27:48 PST 2022


Author: Nikita Popov
Date: 2022-01-04T12:27:40+01:00
New Revision: aefab6f8d5b13c41d000feaa8f0e567d4b6a4681

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

LOG: [InstSimplify] Use weak symbol in test to show miscompile (NFC)

This fold is incorrect, because it assumes that all indices are
non-zero. This happens to be true for the test as written, but
doesn't hold if we use an extern weak global instead, for which
ptrtoint might be zero.

Add separate tests for the simple constant int case.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll b/llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll
index e681c62a4a61..b2d6b3f1c7fb 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll
@@ -65,6 +65,7 @@ define i1 @ult_constexpr_constexpr_one(i8* %x) {
 
 @g = global [2 x i32] [i32 1, i32 2]
 @g2 = global i32 0
+ at g2_weak = extern_weak global i32
 
 define i1 @global_ne_null() {
 ; CHECK-LABEL: @global_ne_null(
@@ -121,7 +122,7 @@ define i1 @null_gep_ne_null() {
 ; CHECK-LABEL: @null_gep_ne_null(
 ; CHECK-NEXT:    ret i1 true
 ;
-  %gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2 to i64)
+  %gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2_weak to i64)
   %cmp = icmp ne i8* %gep, null
   ret i1 %cmp
 }
@@ -130,20 +131,38 @@ define i1 @null_gep_ugt_null() {
 ; CHECK-LABEL: @null_gep_ugt_null(
 ; CHECK-NEXT:    ret i1 true
 ;
-  %gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2 to i64)
+  %gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2_weak to i64)
   %cmp = icmp ugt i8* %gep, null
   ret i1 %cmp
 }
 
 define i1 @null_gep_sgt_null() {
 ; CHECK-LABEL: @null_gep_sgt_null(
-; CHECK-NEXT:    ret i1 icmp sgt (i8* getelementptr (i8, i8* null, i64 ptrtoint (i32* @g2 to i64)), i8* null)
+; CHECK-NEXT:    ret i1 icmp sgt (i8* getelementptr (i8, i8* null, i64 ptrtoint (i32* @g2_weak to i64)), i8* null)
 ;
-  %gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2 to i64)
+  %gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2_weak to i64)
   %cmp = icmp sgt i8* %gep, null
   ret i1 %cmp
 }
 
+define i1 @null_gep_ne_null_constant_int() {
+; CHECK-LABEL: @null_gep_ne_null_constant_int(
+; CHECK-NEXT:    ret i1 true
+;
+  %gep = getelementptr i8, i8* null, i64 1
+  %cmp = icmp ne i8* %gep, null
+  ret i1 %cmp
+}
+
+define i1 @null_gep_ugt_null_constant_int() {
+; CHECK-LABEL: @null_gep_ugt_null_constant_int(
+; CHECK-NEXT:    ret i1 true
+;
+  %gep = getelementptr i8, i8* null, i64 1
+  %cmp = icmp ugt i8* %gep, null
+  ret i1 %cmp
+}
+
 define i1 @null_gep_ne_global() {
 ; CHECK-LABEL: @null_gep_ne_global(
 ; CHECK-NEXT:    ret i1 true


        


More information about the llvm-commits mailing list