Home | History | Annotate | Download | only in InstCombine
      1 ; RUN: opt < %s -instcombine -S | FileCheck %s
      2 
      3 ; CHECK-LABEL: @sub1(
      4 ; CHECK: %y = sub i32 0, %x
      5 ; CHECK: %z = sdiv i32 %y, 337
      6 ; CHECK: ret i32 %z
      7 define i32 @sub1(i32 %x) {
      8   %y = sub i32 0, %x
      9   %z = sdiv i32 %y, 337
     10   ret i32 %z
     11 }
     12 
     13 ; CHECK-LABEL: @sub2(
     14 ; CHECK: %z = sdiv i32 %x, -337
     15 ; CHECK: ret i32 %z
     16 define i32 @sub2(i32 %x) {
     17   %y = sub nsw i32 0, %x
     18   %z = sdiv i32 %y, 337
     19   ret i32 %z
     20 }
     21 
     22 ; CHECK-LABEL: @shl_icmp(
     23 ; CHECK: %B = icmp eq i64 %X, 0
     24 ; CHECK: ret i1 %B
     25 define i1 @shl_icmp(i64 %X) nounwind {
     26   %A = shl nuw i64 %X, 2   ; X/4
     27   %B = icmp eq i64 %A, 0
     28   ret i1 %B
     29 }
     30 
     31 ; CHECK-LABEL: @shl1(
     32 ; CHECK: %B = shl nuw nsw i64 %A, 8
     33 ; CHECK: ret i64 %B
     34 define i64 @shl1(i64 %X, i64* %P) nounwind {
     35   %A = and i64 %X, 312
     36   store i64 %A, i64* %P  ; multiple uses of A.
     37   %B = shl i64 %A, 8
     38   ret i64 %B
     39 }
     40 
     41 ; CHECK-LABEL: @preserve1(
     42 ; CHECK: add nsw i32 %x, 5
     43 define i32 @preserve1(i32 %x) nounwind {
     44   %add = add nsw i32 %x, 2
     45   %add3 = add nsw i32 %add, 3
     46   ret i32 %add3
     47 }
     48 
     49 ; CHECK-LABEL: @nopreserve1(
     50 ; CHECK: add i8 %x, -126
     51 define i8 @nopreserve1(i8 %x) nounwind {
     52   %add = add nsw i8 %x, 127
     53   %add3 = add nsw i8 %add, 3
     54   ret i8 %add3
     55 }
     56 
     57 ; CHECK-LABEL: @nopreserve2(
     58 ; CHECK: add i8 %x, 3
     59 define i8 @nopreserve2(i8 %x) nounwind {
     60   %add = add i8 %x, 1
     61   %add3 = add nsw i8 %add, 2
     62   ret i8 %add3
     63 }
     64 
     65 ; CHECK-LABEL: @nopreserve3(
     66 ; CHECK: add i8 %A, %B
     67 ; CHECK: add i8
     68 define i8 @nopreserve3(i8 %A, i8 %B) nounwind {
     69   %x = add i8 %A, 10
     70   %y = add i8 %B, 10
     71   %add = add nsw i8 %x, %y
     72   ret i8 %add
     73 }
     74 
     75 ; CHECK-LABEL: @nopreserve4(
     76 ; CHECK: add i8 %A, %B
     77 ; CHECK: add i8
     78 define i8 @nopreserve4(i8 %A, i8 %B) nounwind {
     79   %x = add nsw i8 %A, 10
     80   %y = add nsw i8 %B, 10
     81   %add = add nsw i8 %x, %y
     82   ret i8 %add
     83 }
     84