1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=sccp -S | FileCheck %s
4 declare void @use.i32(i32)
5 declare void @use.i1(i1)
7 define void @and_constexpr(i32 %a) {
8 ; CHECK-LABEL: @and_constexpr(
10 ; CHECK-NEXT: call void @use.i32(i32 0)
11 ; CHECK-NEXT: [[AND_2:%.*]] = and i32 20, [[A:%.*]]
12 ; CHECK-NEXT: call void @use.i32(i32 [[AND_2]])
13 ; CHECK-NEXT: call void @use.i1(i1 true)
14 ; CHECK-NEXT: call void @use.i1(i1 false)
15 ; CHECK-NEXT: [[COND_1:%.*]] = icmp eq i32 [[AND_2]], 10
16 ; CHECK-NEXT: call void @use.i1(i1 [[COND_1]])
17 ; CHECK-NEXT: call void @use.i32(i32 4)
18 ; CHECK-NEXT: ret void
21 %and.1 = and i32 ptrtoint (ptr inttoptr (i32 0 to ptr) to i32), %a
22 call void @use.i32(i32 %and.1)
23 %and.2 = and i32 ptrtoint (ptr inttoptr (i32 20 to ptr) to i32), %a
24 call void @use.i32(i32 %and.2)
25 %true.1 = icmp ne i32 %and.2, 100
26 call void @use.i1(i1 %true.1)
27 %false.1 = icmp eq i32 %and.2, 100
28 call void @use.i1(i1 %false.1)
29 %cond.1 = icmp eq i32 %and.2, 10
30 call void @use.i1(i1 %cond.1)
31 %and.3 = and i32 ptrtoint (ptr inttoptr (i32 20 to ptr) to i32), ptrtoint (ptr inttoptr (i32 100 to ptr) to i32)
32 call void @use.i32(i32 %and.3)
36 define void @add_constexpr(i32 %a) {
37 ; CHECK-LABEL: @add_constexpr(
39 ; CHECK-NEXT: [[ADD_1:%.*]] = add nuw nsw i32 0, [[A:%.*]]
40 ; CHECK-NEXT: call void @use.i32(i32 [[ADD_1]])
41 ; CHECK-NEXT: [[ADD_2:%.*]] = add i32 20, [[A]]
42 ; CHECK-NEXT: call void @use.i32(i32 [[ADD_2]])
43 ; CHECK-NEXT: [[COND_1:%.*]] = icmp ne i32 [[ADD_2]], 100
44 ; CHECK-NEXT: call void @use.i1(i1 [[COND_1]])
45 ; CHECK-NEXT: [[COND_2:%.*]] = icmp eq i32 [[ADD_2]], 100
46 ; CHECK-NEXT: call void @use.i1(i1 [[COND_2]])
47 ; CHECK-NEXT: [[COND_3:%.*]] = icmp eq i32 [[ADD_2]], 10
48 ; CHECK-NEXT: call void @use.i1(i1 [[COND_3]])
49 ; CHECK-NEXT: call void @use.i32(i32 120)
50 ; CHECK-NEXT: ret void
53 %add.1 = add i32 ptrtoint (ptr inttoptr (i32 0 to ptr) to i32), %a
54 call void @use.i32(i32 %add.1)
55 %add.2 = add i32 ptrtoint (ptr inttoptr (i32 20 to ptr) to i32), %a
56 call void @use.i32(i32 %add.2)
57 %cond.1 = icmp ne i32 %add.2, 100
58 call void @use.i1(i1 %cond.1)
59 %cond.2 = icmp eq i32 %add.2, 100
60 call void @use.i1(i1 %cond.2)
61 %cond.3 = icmp eq i32 %add.2, 10
62 call void @use.i1(i1 %cond.3)
63 %add.3 = add i32 ptrtoint (ptr inttoptr (i32 20 to ptr) to i32), ptrtoint (ptr inttoptr (i32 100 to ptr) to i32)
64 call void @use.i32(i32 %add.3)
68 define void @mul_constexpr(i32 %a) {
69 ; CHECK-LABEL: @mul_constexpr(
71 ; CHECK-NEXT: call void @use.i32(i32 0)
72 ; CHECK-NEXT: [[MUL_2:%.*]] = mul i32 20, [[A:%.*]]
73 ; CHECK-NEXT: call void @use.i32(i32 [[MUL_2]])
74 ; CHECK-NEXT: [[COND_1:%.*]] = icmp ne i32 [[MUL_2]], 100
75 ; CHECK-NEXT: call void @use.i1(i1 [[COND_1]])
76 ; CHECK-NEXT: [[COND_2:%.*]] = icmp eq i32 [[MUL_2]], 100
77 ; CHECK-NEXT: call void @use.i1(i1 [[COND_2]])
78 ; CHECK-NEXT: [[COND_3:%.*]] = icmp eq i32 [[MUL_2]], 10
79 ; CHECK-NEXT: call void @use.i1(i1 [[COND_3]])
80 ; CHECK-NEXT: call void @use.i32(i32 2000)
81 ; CHECK-NEXT: ret void
84 %mul.1 = mul i32 ptrtoint (ptr inttoptr (i32 0 to ptr) to i32), %a
85 call void @use.i32(i32 %mul.1)
86 %mul.2 = mul i32 ptrtoint (ptr inttoptr (i32 20 to ptr) to i32), %a
87 call void @use.i32(i32 %mul.2)
88 %cond.1 = icmp ne i32 %mul.2, 100
89 call void @use.i1(i1 %cond.1)
90 %cond.2 = icmp eq i32 %mul.2, 100
91 call void @use.i1(i1 %cond.2)
92 %cond.3 = icmp eq i32 %mul.2, 10
93 call void @use.i1(i1 %cond.3)
94 %mul.3 = mul i32 ptrtoint (ptr inttoptr (i32 20 to ptr) to i32), ptrtoint (ptr inttoptr (i32 100 to ptr) to i32)
95 call void @use.i32(i32 %mul.3)
99 define void @udiv_constexpr(i32 %a) {
100 ; CHECK-LABEL: @udiv_constexpr(
102 ; CHECK-NEXT: call void @use.i32(i32 0)
103 ; CHECK-NEXT: [[UDIV_2:%.*]] = udiv i32 20, [[A:%.*]]
104 ; CHECK-NEXT: call void @use.i32(i32 [[UDIV_2]])
105 ; CHECK-NEXT: call void @use.i1(i1 true)
106 ; CHECK-NEXT: call void @use.i1(i1 false)
107 ; CHECK-NEXT: [[COND_1:%.*]] = icmp eq i32 [[UDIV_2]], 10
108 ; CHECK-NEXT: call void @use.i1(i1 [[COND_1]])
109 ; CHECK-NEXT: call void @use.i32(i32 0)
110 ; CHECK-NEXT: ret void
113 %udiv.1 = udiv i32 ptrtoint (ptr inttoptr (i32 0 to ptr) to i32), %a
114 call void @use.i32(i32 %udiv.1)
115 %udiv.2 = udiv i32 ptrtoint (ptr inttoptr (i32 20 to ptr) to i32), %a
116 call void @use.i32(i32 %udiv.2)
117 %true.1 = icmp ne i32 %udiv.2, 100
118 call void @use.i1(i1 %true.1)
119 %false.1 = icmp eq i32 %udiv.2, 50
120 call void @use.i1(i1 %false.1)
121 %cond.1 = icmp eq i32 %udiv.2, 10
122 call void @use.i1(i1 %cond.1)
123 %udiv.3 = udiv i32 ptrtoint (ptr inttoptr (i32 20 to ptr) to i32), ptrtoint (ptr inttoptr (i32 100 to ptr) to i32)
124 call void @use.i32(i32 %udiv.3)