Chad Rosier | b3eb452 | 2014-11-07 22:12:57 +0000 | [diff] [blame^] | 1 | ; RUN: opt < %s -reassociate -dce -S | FileCheck %s |
| 2 | ; PR12985 |
| 3 | |
| 4 | ; Verify the nsw flags are preserved when converting shl to mul. |
| 5 | |
| 6 | ; CHECK-LABEL: @shl_to_mul_nsw( |
| 7 | ; CHECK: %mul = mul i32 %i, -2147483648 |
| 8 | ; CHECK: %mul2 = add i32 %mul, 1 |
| 9 | define i32 @shl_to_mul_nsw(i32 %i) { |
| 10 | entry: |
| 11 | %mul = shl nsw i32 %i, 31 |
| 12 | %mul2 = add i32 %mul, 1 |
| 13 | ret i32 %mul2 |
| 14 | } |
| 15 | |
| 16 | ; CHECK-LABEL: @shl_to_mul_nuw( |
| 17 | ; CHECK: %mul = mul nuw i32 %i, 4 |
| 18 | ; CHECK: %mul2 = add i32 %mul, 1 |
| 19 | define i32 @shl_to_mul_nuw(i32 %i) { |
| 20 | entry: |
| 21 | %mul = shl nuw i32 %i, 2 |
| 22 | %mul2 = add i32 %mul, 1 |
| 23 | ret i32 %mul2 |
| 24 | } |
| 25 | |
| 26 | ; CHECK-LABEL: @shl_to_mul_nuw_nsw( |
| 27 | ; CHECK: %mul = mul nuw nsw i32 %i, 4 |
| 28 | ; CHECK: %mul2 = add i32 %mul, 1 |
| 29 | define i32 @shl_to_mul_nuw_nsw(i32 %i) { |
| 30 | entry: |
| 31 | %mul = shl nuw nsw i32 %i, 2 |
| 32 | %mul2 = add i32 %mul, 1 |
| 33 | ret i32 %mul2 |
| 34 | } |