1 ; RUN: llc -O2 < %s -march=nvptx -mcpu=sm_35 | FileCheck %s --check-prefix=O2 --check-prefix=CHECK
2 ; RUN: llc -O0 < %s -march=nvptx -mcpu=sm_35 | FileCheck %s --check-prefix=O0 --check-prefix=CHECK
9 ; should be transformed into
12 ; rem = n - (n / d) * d
14 ; during NVPTX isel, at -O2. At -O0, we should leave it alone.
16 ; CHECK-LABEL: sdiv32(
17 define void @sdiv32(i32 %n, i32 %d, i32* %quot_ret, i32* %rem_ret) {
18 ; CHECK: div.s32 [[quot:%r[0-9]+]], [[num:%r[0-9]+]], [[den:%r[0-9]+]];
19 %quot = sdiv i32 %n, %d
22 ; (This is unfortunately order-sensitive, even though mul is commutative.)
23 ; O2: mul.lo.s32 [[mul:%r[0-9]+]], [[quot]], [[den]];
24 ; O2: sub.s32 [[rem:%r[0-9]+]], [[num]], [[mul]]
25 %rem = srem i32 %n, %d
27 ; O2: st{{.*}}[[quot]]
28 store i32 %quot, i32* %quot_ret
30 store i32 %rem, i32* %rem_ret
34 ; CHECK-LABEL: udiv32(
35 define void @udiv32(i32 %n, i32 %d, i32* %quot_ret, i32* %rem_ret) {
36 ; CHECK: div.u32 [[quot:%r[0-9]+]], [[num:%r[0-9]+]], [[den:%r[0-9]+]];
37 %quot = udiv i32 %n, %d
41 ; Selection DAG doesn't know whether this is signed or unsigned
42 ; multiplication and subtraction, but it doesn't make a difference either
44 ; O2: mul.lo.{{u|s}}32 [[mul:%r[0-9]+]], [[quot]], [[den]];
45 ; O2: sub.{{u|s}}32 [[rem:%r[0-9]+]], [[num]], [[mul]]
46 %rem = urem i32 %n, %d
48 ; O2: st{{.*}}[[quot]]
49 store i32 %quot, i32* %quot_ret
51 store i32 %rem, i32* %rem_ret
55 ; Check that we don't perform this optimization if one operation is signed and
57 ; CHECK-LABEL: mismatched_types1(
58 define void @mismatched_types1(i32 %n, i32 %d, i32* %quot_ret, i32* %rem_ret) {
61 %quot = udiv i32 %n, %d
62 %rem = srem i32 %n, %d
63 store i32 %quot, i32* %quot_ret
64 store i32 %rem, i32* %rem_ret
68 ; CHECK-LABEL: mismatched_types2(
69 define void @mismatched_types2(i32 %n, i32 %d, i32* %quot_ret, i32* %rem_ret) {
72 %quot = sdiv i32 %n, %d
73 %rem = urem i32 %n, %d
74 store i32 %quot, i32* %quot_ret
75 store i32 %rem, i32* %rem_ret
79 ; Check that we don't perform this optimization if the inputs to the div don't
80 ; match the inputs to the rem.
81 ; CHECK-LABEL: mismatched_inputs1(
82 define void @mismatched_inputs1(i32 %n, i32 %d, i32* %quot_ret, i32* %rem_ret) {
85 %quot = sdiv i32 %n, %d
86 %rem = srem i32 %d, %n
87 store i32 %quot, i32* %quot_ret
88 store i32 %rem, i32* %rem_ret
92 ; CHECK-LABEL: mismatched_inputs2(
93 define void @mismatched_inputs2(i32 %n1, i32 %n2, i32 %d, i32* %quot_ret, i32* %rem_ret) {
96 %quot = sdiv i32 %n1, %d
97 %rem = srem i32 %n2, %d
98 store i32 %quot, i32* %quot_ret
99 store i32 %rem, i32* %rem_ret
103 ; CHECK-LABEL: mismatched_inputs3(
104 define void @mismatched_inputs3(i32 %n, i32 %d1, i32 %d2, i32* %quot_ret, i32* %rem_ret) {
107 %quot = sdiv i32 %n, %d1
108 %rem = srem i32 %n, %d2
109 store i32 %quot, i32* %quot_ret
110 store i32 %rem, i32* %rem_ret