Sanjoy Das | 0e643db | 2018-04-26 20:52:27 +0000 | [diff] [blame^] | 1 | ; RUN: opt < %s -instcombine -S | FileCheck %s |
| 2 | ; ModuleID = 'test/Transforms/InstCombine/add4.ll' |
| 3 | source_filename = "test/Transforms/InstCombine/add4.ll" |
| 4 | |
| 5 | define i64 @match_unsigned(i64 %x) { |
| 6 | ; CHECK-LABEL: @match_unsigned( |
| 7 | ; CHECK: [[TMP:%.*]] = add |
| 8 | ; CHECK-NEXT: ret i64 [[TMP]] |
| 9 | ; |
| 10 | bb: |
| 11 | %tmp = urem i64 %x, 299 |
| 12 | %tmp1 = udiv i64 %x, 299 |
| 13 | %tmp2 = urem i64 %tmp1, 64 |
| 14 | %tmp3 = mul i64 %tmp2, 299 |
| 15 | %tmp4 = add nuw nsw i64 %tmp, %tmp3 |
| 16 | ret i64 %tmp4 |
| 17 | } |
| 18 | |
| 19 | define i64 @match_andAsRem_lshrAsDiv_shlAsMul(i64 %x) { |
| 20 | ; CHECK-LABEL: @match_andAsRem_lshrAsDiv_shlAsMul( |
| 21 | ; CHECK: [[TMP:%.*]] = or |
| 22 | ; CHECK-NEXT: ret i64 [[TMP]] |
| 23 | ; |
| 24 | bb: |
| 25 | %tmp = and i64 %x, 63 |
| 26 | %tmp1 = lshr i64 %x, 6 |
| 27 | %tmp2 = urem i64 %tmp1, 9 |
| 28 | %tmp3 = shl nuw nsw i64 %tmp2, 6 |
| 29 | %tmp4 = add nuw nsw i64 %tmp, %tmp3 |
| 30 | ret i64 %tmp4 |
| 31 | } |
| 32 | |
| 33 | define i64 @match_signed(i64 %x) { |
| 34 | ; CHECK-LABEL: @match_signed( |
| 35 | ; CHECK: [[TMP1:%.*]] = add |
| 36 | ; CHECK: [[TMP2:%.*]] = add |
| 37 | ; CHECK-NEXT: ret i64 [[TMP2]] |
| 38 | ; |
| 39 | bb: |
| 40 | %tmp = srem i64 %x, 299 |
| 41 | %tmp1 = sdiv i64 %x, 299 |
| 42 | %tmp2 = srem i64 %tmp1, 64 |
| 43 | %tmp3 = sdiv i64 %x, 19136 |
| 44 | %tmp4 = srem i64 %tmp3, 9 |
| 45 | %tmp5 = mul nuw nsw i64 %tmp2, 299 |
| 46 | %tmp6 = add nuw nsw i64 %tmp, %tmp5 |
| 47 | %tmp7 = mul nuw nsw i64 %tmp4, 19136 |
| 48 | %tmp8 = add nuw nsw i64 %tmp6, %tmp7 |
| 49 | ret i64 %tmp8 |
| 50 | } |
| 51 | |
| 52 | define i64 @not_match_inconsistent_signs(i64 %x) { |
| 53 | ; CHECK-LABEL: @not_match_inconsistent_signs( |
| 54 | ; CHECK: [[TMP:%.*]] = add |
| 55 | ; CHECK-NEXT: ret i64 [[TMP]] |
| 56 | ; |
| 57 | bb: |
| 58 | %tmp = urem i64 %x, 299 |
| 59 | %tmp1 = sdiv i64 %x, 299 |
| 60 | %tmp2 = urem i64 %tmp1, 64 |
| 61 | %tmp3 = mul i64 %tmp2, 299 |
| 62 | %tmp4 = add nuw nsw i64 %tmp, %tmp3 |
| 63 | ret i64 %tmp4 |
| 64 | } |
| 65 | |
| 66 | define i64 @not_match_inconsistent_values(i64 %x) { |
| 67 | ; CHECK-LABEL: @not_match_inconsistent_values( |
| 68 | ; CHECK: [[TMP:%.*]] = add |
| 69 | ; CHECK-NEXT: ret i64 [[TMP]] |
| 70 | ; |
| 71 | bb: |
| 72 | %tmp = urem i64 %x, 299 |
| 73 | %tmp1 = udiv i64 %x, 29 |
| 74 | %tmp2 = urem i64 %tmp1, 64 |
| 75 | %tmp3 = mul i64 %tmp2, 299 |
| 76 | %tmp4 = add nuw nsw i64 %tmp, %tmp3 |
| 77 | ret i64 %tmp4 |
| 78 | } |