@@ -89,3 +89,73 @@ block0(v0: i32, v1: i32):
8989; run: %test_bxor_ult_ugt(1, 1) == 0
9090; run: %test_bxor_ult_ugt(1, 3) == 1
9191
92+ ;; Rule 1: (x <_s y) & (x >_s y) => false
93+ function %test_slt_sgt(i32, i32) -> i8 fast {
94+ block0(v0: i32, v1: i32):
95+ v2 = icmp slt v0, v1 ; (x <_s y)
96+ v3 = icmp sgt v0, v1 ; (x >_s y)
97+ v4 = band v2, v3 ; (x <_s y) & (x >_s y)
98+ return v4
99+ }
100+
101+ ; run: %test_slt_sgt(42, 24) == 0
102+
103+ ;; Rule 2: (x <_u y) & (x >_u y) => false
104+ function %test_ult_ugt(i32, i32) -> i8 fast {
105+ block0(v0: i32, v1: i32):
106+ v2 = icmp ult v0, v1 ; (x <_u y)
107+ v3 = icmp ugt v0, v1 ; (x >_u y)
108+ v4 = band v2, v3 ; (x <_u y) & (x >_u y)
109+ return v4
110+ }
111+
112+ ; run: %test_ult_ugt(42, 24) == 0
113+
114+ ;; Rule 3: (x <_s y_const) & (x >_u y_const) => false, if y_const < 0
115+ function %test_slt_ugt_neg_const_y(i32) -> i8 fast {
116+ block0(v0: i32):
117+ v1 = iconst.i32 -10 ; y_const = -10. Triggers (i64_lt y 0)
118+ v2 = icmp slt v0, v1 ; (x <_s -10)
119+ v3 = icmp ugt v0, v1 ; (x >_u -10)
120+ v4 = band v2, v3
121+ return v4
122+ }
123+
124+ ; run: %test_slt_ugt_neg_const_y(42) == 0
125+
126+ ;; Rule 4: (x_const <_s y) & (x_const >_u y) => false, if x_const >= 0
127+ function %test_slt_ugt_pos_const_x(i32) -> i8 fast {
128+ block0(v0: i32):
129+ v1 = iconst.i32 10
130+ v2 = icmp slt v1, v0
131+ v3 = icmp ugt v1, v0
132+ v4 = band v2, v3
133+ return v4
134+ }
135+
136+ ; run: %test_slt_ugt_pos_const_x(42) == 0
137+
138+ ;; Rule 5: (x <_u y_const) & (x >_s y_const) => false, if y_const >= 0
139+ function %test_ult_sgt_pos_const_y(i32) -> i8 fast {
140+ block0(v0: i32):
141+ v1 = iconst.i32 10
142+ v2 = icmp ult v0, v1
143+ v3 = icmp sgt v0, v1
144+ v4 = band v2, v3
145+ return v4
146+ }
147+
148+ ; run: %test_ult_sgt_pos_const_y(42) == 0
149+
150+ ;; Rule 6: (x_const <_u y) & (x_const >_s y) => false, if x_const < 0
151+ function %test_ult_sgt_neg_const_x(i32) -> i8 fast {
152+ block0(v0: i32):
153+ v1 = iconst.i32 -10
154+ v2 = icmp ult v1, v0
155+ v3 = icmp sgt v1, v0
156+ v4 = band v2, v3
157+ return v4
158+ }
159+
160+ ; run: %test_ult_sgt_neg_const_x(42) == 0
161+
0 commit comments