Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 ; RUN: llc -mtriple=armv7-unknown-nacl -sfi-branch -filetype=obj %s -o - \ | |
|
eliben
2013/05/03 21:18:55
I wonder if there's a way to hook this pass to opt
sehr
2013/05/03 23:29:05
I have added an invocation under opt.
| |
| 2 ; RUN: | llvm-objdump -disassemble -triple armv7 -mattr=+nacl-trap - \ | |
| 3 ; RUN: | FileCheck %s | |
| 4 | |
| 5 ; Check for all four operators that need guards. | |
| 6 define i32 @mysdiv(i32 %x, i32 %y) #0 { | |
| 7 entry: | |
| 8 %x.addr = alloca i32, align 4 | |
|
eliben
2013/05/03 21:18:55
Could you minimize this repeating test case to som
sehr
2013/05/03 23:29:05
Done.
| |
| 9 %y.addr = alloca i32, align 4 | |
| 10 store i32 %x, i32* %x.addr, align 4 | |
| 11 store i32 %y, i32* %y.addr, align 4 | |
| 12 %0 = load i32* %x.addr, align 4 | |
|
Mark Seaborn
2013/05/03 21:25:36
Remove the loads+stores. You're copying Clang's -
sehr
2013/05/03 23:29:05
Yes, removed.
| |
| 13 %1 = load i32* %y.addr, align 4 | |
| 14 %div1 = sdiv i32 %0, %1 | |
| 15 ; CHECK: cmp r1, #0 | |
|
Mark Seaborn
2013/05/03 21:25:36
It would be better to test at the IR level too. T
sehr
2013/05/03 23:29:05
I am now testing both ways.
sehr
2013/05/03 23:29:05
I am now checking both.
| |
| 16 ; CHECK-NEXT: beq | |
|
eliben
2013/05/03 21:18:55
I'd check that a trap exists too, before the next
sehr
2013/05/03 23:29:05
Done.
| |
| 17 ret i32 %div1 | |
| 18 } | |
| 19 | |
| 20 define i32 @myudiv(i32 %x, i32 %y) #0 { | |
| 21 entry: | |
| 22 %x.addr = alloca i32, align 4 | |
| 23 %y.addr = alloca i32, align 4 | |
| 24 store i32 %x, i32* %x.addr, align 4 | |
| 25 store i32 %y, i32* %y.addr, align 4 | |
| 26 %0 = load i32* %x.addr, align 4 | |
| 27 %1 = load i32* %y.addr, align 4 | |
| 28 %div1 = udiv i32 %0, %1 | |
| 29 ; CHECK: cmp r1, #0 | |
| 30 ; CHECK-NEXT: beq | |
| 31 ret i32 %div1 | |
| 32 } | |
| 33 | |
| 34 define i32 @mysrem(i32 %x, i32 %y) #0 { | |
| 35 entry: | |
| 36 %x.addr = alloca i32, align 4 | |
| 37 %y.addr = alloca i32, align 4 | |
| 38 store i32 %x, i32* %x.addr, align 4 | |
| 39 store i32 %y, i32* %y.addr, align 4 | |
| 40 %0 = load i32* %x.addr, align 4 | |
| 41 %1 = load i32* %y.addr, align 4 | |
| 42 %rem1 = srem i32 %0, %1 | |
| 43 ; CHECK: cmp r1, #0 | |
| 44 ; CHECK-NEXT: beq | |
| 45 ret i32 %rem1 | |
| 46 } | |
| 47 | |
| 48 define i32 @myurem(i32 %x, i32 %y) #0 { | |
| 49 entry: | |
| 50 %x.addr = alloca i32, align 4 | |
| 51 %y.addr = alloca i32, align 4 | |
| 52 store i32 %x, i32* %x.addr, align 4 | |
| 53 store i32 %y, i32* %y.addr, align 4 | |
| 54 %0 = load i32* %x.addr, align 4 | |
| 55 %1 = load i32* %y.addr, align 4 | |
| 56 %rem1 = urem i32 %0, %1 | |
| 57 ; CHECK: cmp r1, #0 | |
| 58 ; CHECK-NEXT: beq | |
| 59 ret i32 %rem1 | |
| 60 } | |
| 61 | |
| 62 ; Divides by non-zero constants should not be guarded. | |
| 63 define i32 @mysdiv_const(i32 %x, i32 %y) #0 { | |
| 64 entry: | |
| 65 %x.addr = alloca i32, align 4 | |
| 66 %y.addr = alloca i32, align 4 | |
| 67 store i32 %x, i32* %x.addr, align 4 | |
| 68 store i32 %y, i32* %y.addr, align 4 | |
| 69 %0 = load i32* %x.addr, align 4 | |
| 70 %div1 = sdiv i32 %0, 10 | |
| 71 ; CHECK-NOT: cmp r1, #0 | |
| 72 ; CHECK-NOT: f0 de fe e7 | |
| 73 ret i32 %div1 | |
| 74 } | |
| 75 | |
| 76 ; Divides by explicit zero should prefixed by a trap. | |
| 77 define i32 @mysdiv_zero(i32 %x, i32 %y) #0 { | |
| 78 entry: | |
| 79 %x.addr = alloca i32, align 4 | |
| 80 %y.addr = alloca i32, align 4 | |
| 81 store i32 %x, i32* %x.addr, align 4 | |
| 82 store i32 %y, i32* %y.addr, align 4 | |
| 83 %0 = load i32* %x.addr, align 4 | |
| 84 %div1 = sdiv i32 %0, 0 | |
| 85 ; CHECK-NOT: cmp r1, #0 | |
| 86 ; CHECK: f0 de fe e7 | |
| 87 ret i32 %div1 | |
| 88 } | |
| 89 | |
| 90 ; Divides at the start of block should be guarded correctly. | |
| 91 define i32 @mysdiv_loop(i32 %x, i32 %y) #0 { | |
| 92 entry: | |
| 93 %x.addr = alloca i32, align 4 | |
| 94 %y.addr = alloca i32, align 4 | |
| 95 store i32 %x, i32* %x.addr, align 4 | |
| 96 store i32 %y, i32* %y.addr, align 4 | |
| 97 %0 = load i32* %x.addr, align 4 | |
| 98 %1 = load i32* %y.addr, align 4 | |
| 99 br label %header | |
| 100 header: | |
| 101 %div1 = sdiv i32 %0, %1 | |
| 102 ; CHECK: cmp r1, #0 | |
| 103 br label %header | |
| 104 ret i32 %div1 | |
| 105 } | |
| 106 | |
| 107 attributes #0 = { nounwind } | |
| OLD | NEW |