1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
8 ; iff x is known non-negative.
10 declare void @llvm.assume(i1)
12 define i8 @t0(i8 %x, i8 %y) {
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: [[DIV1:%.*]] = lshr i8 [[X]], 5
17 ; CHECK-NEXT: [[DIV:%.*]] = sub nsw i8 0, [[DIV1]]
18 ; CHECK-NEXT: ret i8 [[DIV]]
20 %x_is_nonnegative = icmp sge i8 %x, 0
21 call void @llvm.assume(i1 %x_is_nonnegative)
22 %div = sdiv i8 %x, -32
25 define i8 @n1(i8 %x, i8 %y) {
27 ; CHECK-NEXT: [[X_IS_NONNEGATIVE:%.*]] = icmp sgt i8 [[X:%.*]], -2
28 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_IS_NONNEGATIVE]])
29 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[X]], -32
30 ; CHECK-NEXT: ret i8 [[DIV]]
32 %x_is_nonnegative = icmp sge i8 %x, -1 ; could be negative
33 call void @llvm.assume(i1 %x_is_nonnegative)
34 %div = sdiv i8 %x, -32
37 define i8 @n2(i8 %x, i8 %y) {
39 ; CHECK-NEXT: [[X_IS_NONNEGATIVE:%.*]] = icmp sgt i8 [[X:%.*]], -1
40 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_IS_NONNEGATIVE]])
41 ; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[X]], -31
42 ; CHECK-NEXT: ret i8 [[DIV]]
44 %x_is_nonnegative = icmp sge i8 %x, 0
45 call void @llvm.assume(i1 %x_is_nonnegative)
46 %div = sdiv i8 %x, -31 ; not a negative power of two