|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | +; RUN: opt %s -instcombine -S | FileCheck %s |
| 3 | + |
| 4 | +; Fold |
| 5 | +; x s/ (-1 << y) |
| 6 | +; to |
| 7 | +; -(x >> y) |
| 8 | +; iff x is known non-negative. |
| 9 | + |
| 10 | +declare void @llvm.assume(i1) |
| 11 | + |
| 12 | +define i8 @t0(i8 %x, i8 %y) { |
| 13 | +; CHECK-LABEL: @t0( |
| 14 | +; CHECK-NEXT: [[X_IS_NONNEGATIVE:%.*]] = icmp sgt i8 [[X:%.*]], -1 |
| 15 | +; CHECK-NEXT: call void @llvm.assume(i1 [[X_IS_NONNEGATIVE]]) |
| 16 | +; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[X]], -32 |
| 17 | +; CHECK-NEXT: ret i8 [[DIV]] |
| 18 | +; |
| 19 | + %x_is_nonnegative = icmp sge i8 %x, 0 |
| 20 | + call void @llvm.assume(i1 %x_is_nonnegative) |
| 21 | + %div = sdiv i8 %x, -32 |
| 22 | + ret i8 %div |
| 23 | +} |
| 24 | +define i8 @n1(i8 %x, i8 %y) { |
| 25 | +; CHECK-LABEL: @n1( |
| 26 | +; CHECK-NEXT: [[X_IS_NONNEGATIVE:%.*]] = icmp sgt i8 [[X:%.*]], -2 |
| 27 | +; CHECK-NEXT: call void @llvm.assume(i1 [[X_IS_NONNEGATIVE]]) |
| 28 | +; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[X]], -32 |
| 29 | +; CHECK-NEXT: ret i8 [[DIV]] |
| 30 | +; |
| 31 | + %x_is_nonnegative = icmp sge i8 %x, -1 ; could be negative |
| 32 | + call void @llvm.assume(i1 %x_is_nonnegative) |
| 33 | + %div = sdiv i8 %x, -32 |
| 34 | + ret i8 %div |
| 35 | +} |
| 36 | +define i8 @n2(i8 %x, i8 %y) { |
| 37 | +; CHECK-LABEL: @n2( |
| 38 | +; CHECK-NEXT: [[X_IS_NONNEGATIVE:%.*]] = icmp sgt i8 [[X:%.*]], -1 |
| 39 | +; CHECK-NEXT: call void @llvm.assume(i1 [[X_IS_NONNEGATIVE]]) |
| 40 | +; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[X]], -31 |
| 41 | +; CHECK-NEXT: ret i8 [[DIV]] |
| 42 | +; |
| 43 | + %x_is_nonnegative = icmp sge i8 %x, 0 |
| 44 | + call void @llvm.assume(i1 %x_is_nonnegative) |
| 45 | + %div = sdiv i8 %x, -31 ; not a negative power of two |
| 46 | + ret i8 %div |
| 47 | +} |
0 commit comments