Skip to content

Commit bce4b59

Browse files
TerryGuoakiramenai
authored andcommitted
[EraVM] Add negative tests for overflow folding optimizations
Those tests are sub-optimal ones with redundant arithmetic operations which should be optimized out. PR: #591, Issue: #590.
1 parent 4655edd commit bce4b59

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
2+
; RUN: llc -O2 < %s | FileCheck %s
3+
4+
target datalayout = "E-p:256:256-i256:256:256-S32-a:256:256"
5+
target triple = "eravm"
6+
7+
declare { i256, i1 } @llvm.uadd.with.overflow.i256(i256, i256)
8+
declare void @has_overflow(i256)
9+
declare void @has_no_overflow(i256)
10+
11+
; TODO: #590 x + y is computed twice which is redundant
12+
define i256 @add_test_neg_1(i256 %a, i256 %b, i256 %x, i256 %y) {
13+
; CHECK-LABEL: add_test_neg_1:
14+
; CHECK: ; %bb.0: ; %entry
15+
; CHECK-NEXT: add! r3, r4, r5
16+
; CHECK-NEXT: add.lt r1, r0, r2
17+
; CHECK-NEXT: add r3, r4, r1
18+
; CHECK-NEXT: add r1, r2, r1
19+
; CHECK-NEXT: ret
20+
entry:
21+
%res1 = call {i256, i1} @llvm.uadd.with.overflow.i256(i256 %x, i256 %y)
22+
%res2 = extractvalue {i256, i1} %res1, 0
23+
%overflow = extractvalue {i256, i1} %res1, 1
24+
%selected = select i1 %overflow, i256 %a, i256 %b
25+
%sum = add i256 %res2, %selected
26+
ret i256 %sum
27+
}
28+
29+
; TODO: #590 x + y is computed twice which is redundant
30+
define void @add_branch_neg_1(i256 %x, i256 %y) {
31+
; CHECK-LABEL: add_branch_neg_1:
32+
; CHECK: ; %bb.0: ; %entry
33+
; CHECK-NEXT: add r1, r0, r3
34+
; CHECK-NEXT: add r3, r2, r1
35+
; CHECK-NEXT: add! r3, r2, r2
36+
; CHECK-NEXT: jump.lt @.BB1_2
37+
; CHECK-NEXT: ; %bb.1: ; %no_overflow_detected
38+
; CHECK-NEXT: near_call r0, @has_no_overflow, @DEFAULT_UNWIND
39+
; CHECK-NEXT: ret
40+
; CHECK-NEXT: .BB1_2: ; %overflow_detected
41+
; CHECK-NEXT: near_call r0, @has_overflow, @DEFAULT_UNWIND
42+
; CHECK-NEXT: ret
43+
entry:
44+
%res1 = call {i256, i1} @llvm.uadd.with.overflow.i256(i256 %x, i256 %y)
45+
%sum = extractvalue {i256, i1} %res1, 0
46+
%overflow = extractvalue {i256, i1} %res1, 1
47+
br i1 %overflow, label %overflow_detected, label %no_overflow_detected
48+
49+
overflow_detected:
50+
call void @has_overflow(i256 %sum)
51+
br label %exit
52+
53+
no_overflow_detected:
54+
call void @has_no_overflow(i256 %sum)
55+
br label %exit
56+
57+
exit:
58+
ret void
59+
}

0 commit comments

Comments
 (0)