Skip to content

Commit aefab6f

Browse files
committed
[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.
1 parent 6231ef2 commit aefab6f

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ define i1 @ult_constexpr_constexpr_one(i8* %x) {
6565

6666
@g = global [2 x i32] [i32 1, i32 2]
6767
@g2 = global i32 0
68+
@g2_weak = extern_weak global i32
6869

6970
define i1 @global_ne_null() {
7071
; CHECK-LABEL: @global_ne_null(
@@ -121,7 +122,7 @@ define i1 @null_gep_ne_null() {
121122
; CHECK-LABEL: @null_gep_ne_null(
122123
; CHECK-NEXT: ret i1 true
123124
;
124-
%gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2 to i64)
125+
%gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2_weak to i64)
125126
%cmp = icmp ne i8* %gep, null
126127
ret i1 %cmp
127128
}
@@ -130,20 +131,38 @@ define i1 @null_gep_ugt_null() {
130131
; CHECK-LABEL: @null_gep_ugt_null(
131132
; CHECK-NEXT: ret i1 true
132133
;
133-
%gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2 to i64)
134+
%gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2_weak to i64)
134135
%cmp = icmp ugt i8* %gep, null
135136
ret i1 %cmp
136137
}
137138

138139
define i1 @null_gep_sgt_null() {
139140
; CHECK-LABEL: @null_gep_sgt_null(
140-
; CHECK-NEXT: ret i1 icmp sgt (i8* getelementptr (i8, i8* null, i64 ptrtoint (i32* @g2 to i64)), i8* null)
141+
; CHECK-NEXT: ret i1 icmp sgt (i8* getelementptr (i8, i8* null, i64 ptrtoint (i32* @g2_weak to i64)), i8* null)
141142
;
142-
%gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2 to i64)
143+
%gep = getelementptr i8, i8* null, i64 ptrtoint (i32* @g2_weak to i64)
143144
%cmp = icmp sgt i8* %gep, null
144145
ret i1 %cmp
145146
}
146147

148+
define i1 @null_gep_ne_null_constant_int() {
149+
; CHECK-LABEL: @null_gep_ne_null_constant_int(
150+
; CHECK-NEXT: ret i1 true
151+
;
152+
%gep = getelementptr i8, i8* null, i64 1
153+
%cmp = icmp ne i8* %gep, null
154+
ret i1 %cmp
155+
}
156+
157+
define i1 @null_gep_ugt_null_constant_int() {
158+
; CHECK-LABEL: @null_gep_ugt_null_constant_int(
159+
; CHECK-NEXT: ret i1 true
160+
;
161+
%gep = getelementptr i8, i8* null, i64 1
162+
%cmp = icmp ugt i8* %gep, null
163+
ret i1 %cmp
164+
}
165+
147166
define i1 @null_gep_ne_global() {
148167
; CHECK-LABEL: @null_gep_ne_global(
149168
; CHECK-NEXT: ret i1 true

0 commit comments

Comments
 (0)