Skip to content

Commit 9b183a1

Browse files
committed
[NFC][InstSimplify] Add miscompiled testcase from D87188/D87197
Thanks to Dave Green for producing an actionable reproducer! It is (obviously) a miscompile: ``` ---------------------------------------- define i32 @select_abs_of_abs_eq_wrong(i32 %x, i32 %y) { %0: %abs = abs i32 %x, 0 %neg = sub i32 0, %abs %cmp = icmp eq i32 %y, 0 %sel = select i1 %cmp, i32 %neg, i32 %abs ret i32 %sel } => define i32 @select_abs_of_abs_eq_wrong(i32 %x, i32 %y) { %0: %abs = abs i32 %x, 0 ret i32 %abs } Transformation doesn't verify! ERROR: Value mismatch Example: i32 %x = #xe0000000 (3758096384, -536870912) i32 %y = #x00000000 (0) Source: i32 %abs = #x20000000 (536870912) i32 %neg = #xe0000000 (3758096384, -536870912) i1 %cmp = #x1 (1) i32 %sel = #xe0000000 (3758096384, -536870912) Target: i32 %abs = #x20000000 (536870912) Source value: #xe0000000 (3758096384, -536870912) Target value: #x20000000 (536870912) Alive2: Transform doesn't verify! ```
1 parent 5f75dcf commit 9b183a1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

llvm/test/Transforms/InstSimplify/abs_intrinsic.ll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@ define i32 @select_abs_of_abs_eq(i32 %x) {
221221
ret i32 %sel
222222
}
223223

224+
; The comparison is not with the same value we take abs() of, so this isn't the pattern.
225+
define i32 @select_abs_of_abs_eq_wrong(i32 %x, i32 %y) {
226+
; CHECK-LABEL: @select_abs_of_abs_eq_wrong(
227+
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
228+
; CHECK-NEXT: ret i32 [[ABS]]
229+
;
230+
%abs = call i32 @llvm.abs.i32(i32 %x, i1 false)
231+
%neg = sub i32 0, %abs
232+
%cmp = icmp eq i32 %y, 0 ; not %x
233+
%sel = select i1 %cmp, i32 %neg, i32 %abs
234+
ret i32 %sel
235+
}
236+
224237
define i32 @select_abs_of_abs_ne(i32 %x) {
225238
; CHECK-LABEL: @select_abs_of_abs_ne(
226239
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
@@ -246,6 +259,20 @@ define i32 @select_nabs_of_abs_eq(i32 %x) {
246259
ret i32 %sel
247260
}
248261

262+
; The comparison is not with the same value we take abs() of, so this isn't the pattern.
263+
define i32 @select_nabs_of_abs_eq_wrong(i32 %x, i32 %y) {
264+
; CHECK-LABEL: @select_nabs_of_abs_eq_wrong(
265+
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
266+
; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[ABS]]
267+
; CHECK-NEXT: ret i32 [[NEG]]
268+
;
269+
%abs = call i32 @llvm.abs.i32(i32 %x, i1 false)
270+
%neg = sub i32 0, %abs
271+
%cmp = icmp eq i32 %y, 0
272+
%sel = select i1 %cmp, i32 %abs, i32 %neg
273+
ret i32 %sel
274+
}
275+
249276
define i32 @select_nabs_of_abs_ne(i32 %x) {
250277
; CHECK-LABEL: @select_nabs_of_abs_ne(
251278
; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)

0 commit comments

Comments
 (0)