1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
3 ; ModuleID = 'test/Transforms/InstCombine/add4.ll'
4 source_filename = "test/Transforms/InstCombine/add4.ll"
6 define i64 @match_unsigned(i64 %x) {
7 ; CHECK-LABEL: @match_unsigned(
9 ; CHECK-NEXT: [[UREM:%.*]] = urem i64 [[X:%.*]], 19136
10 ; CHECK-NEXT: ret i64 [[UREM]]
13 %tmp = urem i64 %x, 299
14 %tmp1 = udiv i64 %x, 299
15 %tmp2 = urem i64 %tmp1, 64
16 %tmp3 = mul i64 %tmp2, 299
17 %tmp4 = add i64 %tmp, %tmp3
21 define i64 @match_andAsRem_lshrAsDiv_shlAsMul(i64 %x) {
22 ; CHECK-LABEL: @match_andAsRem_lshrAsDiv_shlAsMul(
24 ; CHECK-NEXT: [[UREM:%.*]] = urem i64 [[X:%.*]], 576
25 ; CHECK-NEXT: ret i64 [[UREM]]
29 %tmp1 = lshr i64 %x, 6
30 %tmp2 = urem i64 %tmp1, 9
31 %tmp3 = shl i64 %tmp2, 6
32 %tmp4 = add i64 %tmp, %tmp3
36 define i64 @match_signed(i64 %x) {
37 ; CHECK-LABEL: @match_signed(
39 ; CHECK-NEXT: [[SREM1:%.*]] = srem i64 [[X:%.*]], 172224
40 ; CHECK-NEXT: ret i64 [[SREM1]]
43 %tmp = srem i64 %x, 299
44 %tmp1 = sdiv i64 %x, 299
45 %tmp2 = srem i64 %tmp1, 64
46 %tmp3 = sdiv i64 %x, 19136
47 %tmp4 = srem i64 %tmp3, 9
48 %tmp5 = mul i64 %tmp2, 299
49 %tmp6 = add i64 %tmp, %tmp5
50 %tmp7 = mul i64 %tmp4, 19136
51 %tmp8 = add i64 %tmp6, %tmp7
55 define i64 @not_match_inconsistent_signs(i64 %x) {
56 ; CHECK-LABEL: @not_match_inconsistent_signs(
58 ; CHECK-NEXT: [[TMP:%.*]] = urem i64 [[X:%.*]], 299
59 ; CHECK-NEXT: [[TMP1:%.*]] = sdiv i64 [[X]], 299
60 ; CHECK-NEXT: [[TMP2:%.*]] = and i64 [[TMP1]], 63
61 ; CHECK-NEXT: [[TMP3:%.*]] = mul nuw nsw i64 [[TMP2]], 299
62 ; CHECK-NEXT: [[TMP4:%.*]] = add nuw nsw i64 [[TMP]], [[TMP3]]
63 ; CHECK-NEXT: ret i64 [[TMP4]]
66 %tmp = urem i64 %x, 299
67 %tmp1 = sdiv i64 %x, 299
68 %tmp2 = urem i64 %tmp1, 64
69 %tmp3 = mul i64 %tmp2, 299
70 %tmp4 = add i64 %tmp, %tmp3
74 define i64 @not_match_inconsistent_values(i64 %x) {
75 ; CHECK-LABEL: @not_match_inconsistent_values(
77 ; CHECK-NEXT: [[TMP:%.*]] = urem i64 [[X:%.*]], 299
78 ; CHECK-NEXT: [[TMP1:%.*]] = udiv i64 [[X]], 29
79 ; CHECK-NEXT: [[TMP2:%.*]] = and i64 [[TMP1]], 63
80 ; CHECK-NEXT: [[TMP3:%.*]] = mul nuw nsw i64 [[TMP2]], 299
81 ; CHECK-NEXT: [[TMP4:%.*]] = add nuw nsw i64 [[TMP]], [[TMP3]]
82 ; CHECK-NEXT: ret i64 [[TMP4]]
85 %tmp = urem i64 %x, 299
86 %tmp1 = udiv i64 %x, 29
87 %tmp2 = urem i64 %tmp1, 64
88 %tmp3 = mul i64 %tmp2, 299
89 %tmp4 = add i64 %tmp, %tmp3
93 define i32 @not_match_overflow(i32 %x) {
94 ; CHECK-LABEL: @not_match_overflow(
96 ; CHECK-NEXT: [[TMP:%.*]] = urem i32 [[X:%.*]], 299
97 ; CHECK-NEXT: [[TMP0:%.*]] = urem i32 [[X]], 299
98 ; CHECK-NEXT: [[TMP3:%.*]] = sub i32 [[X]], [[TMP0]]
99 ; CHECK-NEXT: [[TMP4:%.*]] = add i32 [[TMP]], [[TMP3]]
100 ; CHECK-NEXT: ret i32 [[TMP4]]
103 %tmp = urem i32 %x, 299
104 %tmp1 = udiv i32 %x,299
105 %tmp2 = urem i32 %tmp1, 147483647
106 %tmp3 = mul i32 %tmp2, 299
107 %tmp4 = add i32 %tmp, %tmp3