Chris Lattner | 9e4aa02 | 2011-02-09 17:15:04 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -instsimplify -S | FileCheck %s |
| 2 | |
| 3 | ; PR8862 |
| 4 | |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 5 | ; CHECK-LABEL: @shift1( |
Chris Lattner | 9e4aa02 | 2011-02-09 17:15:04 +0000 | [diff] [blame] | 6 | ; CHECK: ret i32 %A |
| 7 | define i32 @shift1(i32 %A, i32 %B) { |
| 8 | %C = lshr exact i32 %A, %B |
| 9 | %D = shl nuw i32 %C, %B |
| 10 | ret i32 %D |
| 11 | } |
| 12 | |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 13 | ; CHECK-LABEL: @shift2( |
Chris Lattner | 9e4aa02 | 2011-02-09 17:15:04 +0000 | [diff] [blame] | 14 | ; CHECK: lshr |
| 15 | ; CHECK: ret i32 %D |
| 16 | define i32 @shift2(i32 %A, i32 %B) { |
| 17 | %C = lshr i32 %A, %B |
| 18 | %D = shl nuw i32 %C, %B |
| 19 | ret i32 %D |
| 20 | } |
| 21 | |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 22 | ; CHECK-LABEL: @shift3( |
Chris Lattner | 9e4aa02 | 2011-02-09 17:15:04 +0000 | [diff] [blame] | 23 | ; CHECK: ret i32 %A |
| 24 | define i32 @shift3(i32 %A, i32 %B) { |
| 25 | %C = ashr exact i32 %A, %B |
| 26 | %D = shl nuw i32 %C, %B |
| 27 | ret i32 %D |
| 28 | } |
| 29 | |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 30 | ; CHECK-LABEL: @shift4( |
Chris Lattner | 9e4aa02 | 2011-02-09 17:15:04 +0000 | [diff] [blame] | 31 | ; CHECK: ret i32 %A |
| 32 | define i32 @shift4(i32 %A, i32 %B) { |
| 33 | %C = shl nuw i32 %A, %B |
| 34 | %D = lshr i32 %C, %B |
| 35 | ret i32 %D |
| 36 | } |
| 37 | |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 38 | ; CHECK-LABEL: @shift5( |
Chris Lattner | 9e4aa02 | 2011-02-09 17:15:04 +0000 | [diff] [blame] | 39 | ; CHECK: ret i32 %A |
| 40 | define i32 @shift5(i32 %A, i32 %B) { |
| 41 | %C = shl nsw i32 %A, %B |
| 42 | %D = ashr i32 %C, %B |
| 43 | ret i32 %D |
| 44 | } |
David Majnemer | cb9d596 | 2014-10-11 10:20:01 +0000 | [diff] [blame] | 45 | |
| 46 | ; CHECK-LABEL: @div1( |
| 47 | ; CHECK: ret i32 0 |
| 48 | define i32 @div1(i32 %V) { |
| 49 | %A = udiv i32 %V, -2147483648 |
| 50 | %B = udiv i32 %A, -2147483648 |
| 51 | ret i32 %B |
| 52 | } |
| 53 | |
| 54 | ; CHECK-LABEL: @div2( |
| 55 | ; CHECK-NOT: ret i32 0 |
| 56 | define i32 @div2(i32 %V) { |
| 57 | %A = sdiv i32 %V, -1 |
| 58 | %B = sdiv i32 %A, -2147483648 |
| 59 | ret i32 %B |
| 60 | } |