Home | History | Annotate | Download | only in InstSimplify
      1 ; RUN: opt < %s -instsimplify -S | FileCheck %s
      2 
      3 ; PR8862
      4 
      5 ; CHECK-LABEL: @shift1(
      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 
     13 ; CHECK-LABEL: @shift2(
     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 
     22 ; CHECK-LABEL: @shift3(
     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 
     30 ; CHECK-LABEL: @shift4(
     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 
     38 ; CHECK-LABEL: @shift5(
     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 }
     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 }
     61