Home | History | Annotate | Download | only in SimplifyCFG
      1 ; RUN: opt -simplifycfg -S < %s | FileCheck %s
      2 
      3 ; We could hoist the div/rem in these tests because it's safe to do so.
      4 ; PR31028 - https://bugs.llvm.org/show_bug.cgi?id=31028
      5 ; ...but since there's a separate pass for that, don't bother.
      6 
      7 define i32 @hoist_sdiv(i32 %a, i32 %b) {
      8 ; CHECK-LABEL: @hoist_sdiv(
      9 ; CHECK-NEXT:  entry:
     10 ; CHECK-NEXT:    [[REM:%.*]] = srem i32 %a, %b
     11 ; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[REM]], 42
     12 ; CHECK-NEXT:    br i1 [[CMP]], label %if, label %end
     13 ; CHECK:       if:
     14 ; CHECK-NEXT:    [[DIV:%.*]] = sdiv i32 %a, %b
     15 ; CHECK-NEXT:    br label %end
     16 ; CHECK:       end:
     17 ; CHECK-NEXT:    [[RET:%.*]] = phi i32 [ [[DIV]], %if ], [ 3, %entry ]
     18 ; CHECK-NEXT:    ret i32 [[RET]]
     19 ;
     20 entry:
     21   %rem = srem i32 %a, %b
     22   %cmp = icmp eq i32 %rem, 42
     23   br i1 %cmp, label %if, label %end
     24 
     25 if:
     26   %div = sdiv i32 %a, %b
     27   br label %end
     28 
     29 end:
     30   %ret = phi i32 [ %div, %if ], [ 3, %entry ]
     31   ret i32 %ret
     32 }
     33 
     34 define i64 @hoist_udiv(i64 %a, i64 %b) {
     35 ; CHECK-LABEL: @hoist_udiv(
     36 ; CHECK-NEXT:  entry:
     37 ; CHECK-NEXT:    [[REM:%.*]] = urem i64 %a, %b
     38 ; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i64 [[REM]], 42
     39 ; CHECK-NEXT:    br i1 [[CMP]], label %if, label %end
     40 ; CHECK:       if:
     41 ; CHECK-NEXT:    [[DIV:%.*]] = udiv i64 %a, %b
     42 ; CHECK-NEXT:    br label %end
     43 ; CHECK:       end:
     44 ; CHECK-NEXT:    [[RET:%.*]] = phi i64 [ [[DIV]], %if ], [ 3, %entry ]
     45 ; CHECK-NEXT:    ret i64 [[RET]]
     46 ;
     47 entry:
     48   %rem = urem i64 %a, %b
     49   %cmp = icmp eq i64 %rem, 42
     50   br i1 %cmp, label %if, label %end
     51 
     52 if:
     53   %div = udiv i64 %a, %b
     54   br label %end
     55 
     56 end:
     57   %ret = phi i64 [ %div, %if ], [ 3, %entry ]
     58   ret i64 %ret
     59 }
     60 
     61 define i16 @hoist_srem(i16 %a, i16 %b) {
     62 ; CHECK-LABEL: @hoist_srem(
     63 ; CHECK-NEXT:  entry:
     64 ; CHECK-NEXT:    [[DIV:%.*]] = sdiv i16 %a, %b
     65 ; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i16 [[DIV]], 42
     66 ; CHECK-NEXT:    br i1 [[CMP]], label %if, label %end
     67 ; CHECK:       if:
     68 ; CHECK-NEXT:    [[REM:%.*]] = srem i16 %a, %b
     69 ; CHECK-NEXT:    br label %end
     70 ; CHECK:       end:
     71 ; CHECK-NEXT:    [[RET:%.*]] = phi i16 [ [[REM]], %if ], [ 3, %entry ]
     72 ; CHECK-NEXT:    ret i16 [[RET]]
     73 ;
     74 entry:
     75   %div = sdiv i16 %a, %b
     76   %cmp = icmp eq i16 %div, 42
     77   br i1 %cmp, label %if, label %end
     78 
     79 if:
     80   %rem = srem i16 %a, %b
     81   br label %end
     82 
     83 end:
     84   %ret = phi i16 [ %rem, %if ], [ 3, %entry ]
     85   ret i16 %ret
     86 }
     87 
     88 define i8 @hoist_urem(i8 %a, i8 %b) {
     89 ; CHECK-LABEL: @hoist_urem(
     90 ; CHECK-NEXT:  entry:
     91 ; CHECK-NEXT:    [[DIV:%.*]] = udiv i8 %a, %b
     92 ; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i8 [[DIV]], 42
     93 ; CHECK-NEXT:    br i1 [[CMP]], label %if, label %end
     94 ; CHECK:       if:
     95 ; CHECK-NEXT:    [[REM:%.*]] = urem i8 %a, %b
     96 ; CHECK-NEXT:    br label %end
     97 ; CHECK:       end:
     98 ; CHECK-NEXT:    [[RET:%.*]] = phi i8 [ [[REM]], %if ], [ 3, %entry ]
     99 ; CHECK-NEXT:    ret i8 [[RET]]
    100 ;
    101 entry:
    102   %div = udiv i8 %a, %b
    103   %cmp = icmp eq i8 %div, 42
    104   br i1 %cmp, label %if, label %end
    105 
    106 if:
    107   %rem = urem i8 %a, %b
    108   br label %end
    109 
    110 end:
    111   %ret = phi i8 [ %rem, %if ], [ 3, %entry ]
    112   ret i8 %ret
    113 }
    114 
    115