1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
11 ; can then be simplified to
14 declare void @use8(i8)
15 declare void @use2xi8(<2 x i8>)
17 define i8 @t0_basic(i8 %x, i8 %y) {
18 ; CHECK-LABEL: @t0_basic(
19 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[X:%.*]], [[Y:%.*]]
20 ; CHECK-NEXT: call void @use8(i8 [[DIV]])
21 ; CHECK-NEXT: [[ROUNDXDOWNTOMULTIPLEOFY:%.*]] = mul i8 [[DIV]], [[Y]]
22 ; CHECK-NEXT: [[REM:%.*]] = sub i8 [[X]], [[ROUNDXDOWNTOMULTIPLEOFY]]
23 ; CHECK-NEXT: ret i8 [[REM]]
26 call void @use8(i8 %div)
27 %roundXdownToMultipleOfY = mul i8 %div, %y
28 %rem = sub i8 %x, %roundXdownToMultipleOfY
32 define <2 x i8> @t1_vector(<2 x i8> %x, <2 x i8> %y) {
33 ; CHECK-LABEL: @t1_vector(
34 ; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i8> [[X:%.*]], [[Y:%.*]]
35 ; CHECK-NEXT: call void @use2xi8(<2 x i8> [[DIV]])
36 ; CHECK-NEXT: [[ROUNDXDOWNTOMULTIPLEOFY:%.*]] = mul <2 x i8> [[DIV]], [[Y]]
37 ; CHECK-NEXT: [[REM:%.*]] = sub <2 x i8> [[X]], [[ROUNDXDOWNTOMULTIPLEOFY]]
38 ; CHECK-NEXT: ret <2 x i8> [[REM]]
40 %div = sdiv <2 x i8> %x, %y
41 call void @use2xi8(<2 x i8> %div)
42 %roundXdownToMultipleOfY = mul <2 x i8> %div, %y
43 %rem = sub <2 x i8> %x, %roundXdownToMultipleOfY
49 define i8 @t4_extrause(i8 %x, i8 %y) {
50 ; CHECK-LABEL: @t4_extrause(
51 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[X:%.*]], [[Y:%.*]]
52 ; CHECK-NEXT: call void @use8(i8 [[DIV]])
53 ; CHECK-NEXT: [[ROUNDXDOWNTOMULTIPLEOFY:%.*]] = mul i8 [[DIV]], [[Y]]
54 ; CHECK-NEXT: call void @use8(i8 [[ROUNDXDOWNTOMULTIPLEOFY]])
55 ; CHECK-NEXT: [[REM:%.*]] = sub i8 [[X]], [[ROUNDXDOWNTOMULTIPLEOFY]]
56 ; CHECK-NEXT: ret i8 [[REM]]
59 call void @use8(i8 %div)
60 %roundXdownToMultipleOfY = mul i8 %div, %y
61 call void @use8(i8 %roundXdownToMultipleOfY)
62 %rem = sub i8 %x, %roundXdownToMultipleOfY
70 define i8 @t5_commutative(i8 %x) {
71 ; CHECK-LABEL: @t5_commutative(
72 ; CHECK-NEXT: [[Y:%.*]] = call i8 @gen8()
73 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[X:%.*]], [[Y]]
74 ; CHECK-NEXT: call void @use8(i8 [[DIV]])
75 ; CHECK-NEXT: [[ROUNDXDOWNTOMULTIPLEOFY:%.*]] = mul i8 [[Y]], [[DIV]]
76 ; CHECK-NEXT: [[REM:%.*]] = sub i8 [[X]], [[ROUNDXDOWNTOMULTIPLEOFY]]
77 ; CHECK-NEXT: ret i8 [[REM]]
81 call void @use8(i8 %div)
82 %roundXdownToMultipleOfY = mul i8 %y, %div ; swapped
83 %rem = sub i8 %x, %roundXdownToMultipleOfY
89 define i8 @n6_different_x(i8 %x0, i8 %x1, i8 %y) {
90 ; CHECK-LABEL: @n6_different_x(
91 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[X0:%.*]], [[Y:%.*]]
92 ; CHECK-NEXT: call void @use8(i8 [[DIV]])
93 ; CHECK-NEXT: [[ROUNDXDOWNTOMULTIPLEOFY:%.*]] = mul i8 [[DIV]], [[Y]]
94 ; CHECK-NEXT: [[REM:%.*]] = sub i8 [[X1:%.*]], [[ROUNDXDOWNTOMULTIPLEOFY]]
95 ; CHECK-NEXT: ret i8 [[REM]]
97 %div = sdiv i8 %x0, %y
98 call void @use8(i8 %div)
99 %roundXdownToMultipleOfY = mul i8 %div, %y
100 %rem = sub i8 %x1, %roundXdownToMultipleOfY
104 define i8 @n6_different_y(i8 %x, i8 %y0, i8 %y1) {
105 ; CHECK-LABEL: @n6_different_y(
106 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[X:%.*]], [[Y0:%.*]]
107 ; CHECK-NEXT: call void @use8(i8 [[DIV]])
108 ; CHECK-NEXT: [[ROUNDXDOWNTOMULTIPLEOFY:%.*]] = mul i8 [[DIV]], [[Y1:%.*]]
109 ; CHECK-NEXT: [[REM:%.*]] = sub i8 [[X]], [[ROUNDXDOWNTOMULTIPLEOFY]]
110 ; CHECK-NEXT: ret i8 [[REM]]
112 %div = sdiv i8 %x, %y0
113 call void @use8(i8 %div)
114 %roundXdownToMultipleOfY = mul i8 %div, %y1
115 %rem = sub i8 %x, %roundXdownToMultipleOfY