Skip to content

Commit c83180c

Browse files
committed
[ConstraintElim] Add tests for llvm#78621.
Tests with umin where the result may be poison for llvm#78621.
1 parent 78d8ce3 commit c83180c

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2+
; RUN: opt -p constraint-elimination -S %s | FileCheck %s
3+
4+
; Tests for https://github.com/llvm/llvm-project/issues/78621.
5+
6+
define i1 @umin_not_used(i32 %arg) {
7+
; CHECK-LABEL: define i1 @umin_not_used(
8+
; CHECK-SAME: i32 [[ARG:%.*]]) {
9+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i32 [[ARG]], 3
10+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.umin.i32(i32 [[SHL]], i32 80)
11+
; CHECK-NEXT: [[CMP2:%.*]] = shl nuw nsw i32 [[ARG]], 3
12+
; CHECK-NEXT: ret i1 false
13+
;
14+
%icmp = icmp slt i32 %arg, 0
15+
%shl = shl nuw nsw i32 %arg, 3
16+
call i32 @llvm.umin.i32(i32 %shl, i32 80)
17+
%cmp2 = shl nuw nsw i32 %arg, 3
18+
ret i1 %icmp
19+
}
20+
21+
define i1 @umin_poison_is_UB_via_call(i32 %arg) {
22+
; CHECK-LABEL: define i1 @umin_poison_is_UB_via_call(
23+
; CHECK-SAME: i32 [[ARG:%.*]]) {
24+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i32 [[ARG]], 3
25+
; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[SHL]], i32 80)
26+
; CHECK-NEXT: call void @noundef(i32 noundef [[MIN]])
27+
; CHECK-NEXT: [[CMP2:%.*]] = shl nuw nsw i32 [[ARG]], 3
28+
; CHECK-NEXT: ret i1 false
29+
;
30+
%icmp = icmp slt i32 %arg, 0
31+
%shl = shl nuw nsw i32 %arg, 3
32+
%min = call i32 @llvm.umin.i32(i32 %shl, i32 80)
33+
call void @noundef(i32 noundef %min)
34+
%cmp2 = shl nuw nsw i32 %arg, 3
35+
ret i1 %icmp
36+
}
37+
38+
define i1 @umin_poison_call_before_UB(i32 %arg) {
39+
; CHECK-LABEL: define i1 @umin_poison_call_before_UB(
40+
; CHECK-SAME: i32 [[ARG:%.*]]) {
41+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i32 [[ARG]], 3
42+
; CHECK-NEXT: [[MIN:%.*]] = call i32 @llvm.umin.i32(i32 [[SHL]], i32 80)
43+
; CHECK-NEXT: call void @fn()
44+
; CHECK-NEXT: call void @noundef(i32 noundef [[MIN]])
45+
; CHECK-NEXT: [[CMP2:%.*]] = shl nuw nsw i32 [[ARG]], 3
46+
; CHECK-NEXT: ret i1 false
47+
;
48+
%icmp = icmp slt i32 %arg, 0
49+
%shl = shl nuw nsw i32 %arg, 3
50+
%min = call i32 @llvm.umin.i32(i32 %shl, i32 80)
51+
call void @fn()
52+
call void @noundef(i32 noundef %min)
53+
%cmp2 = shl nuw nsw i32 %arg, 3
54+
ret i1 %icmp
55+
}
56+
57+
declare i32 @llvm.umin.i32(i32, i32) #0
58+
59+
declare void @noundef(i32 noundef)
60+
declare void @fn()

0 commit comments

Comments
 (0)