49 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4; Fold5; x s/ (-1 << y)6; to7; -(x >> y)8; iff x is known non-negative.9 10declare void @llvm.assume(i1)11 12define i8 @t0(i8 %x, i8 %y) {13; CHECK-LABEL: @t0(14; CHECK-NEXT: [[X_IS_NONNEGATIVE:%.*]] = icmp sgt i8 [[X:%.*]], -115; CHECK-NEXT: call void @llvm.assume(i1 [[X_IS_NONNEGATIVE]])16; CHECK-NEXT: [[DIV1:%.*]] = lshr i8 [[X]], 517; CHECK-NEXT: [[DIV:%.*]] = sub nsw i8 0, [[DIV1]]18; CHECK-NEXT: ret i8 [[DIV]]19;20 %x_is_nonnegative = icmp sge i8 %x, 021 call void @llvm.assume(i1 %x_is_nonnegative)22 %div = sdiv i8 %x, -3223 ret i8 %div24}25define i8 @n1(i8 %x, i8 %y) {26; CHECK-LABEL: @n1(27; CHECK-NEXT: [[X_IS_NONNEGATIVE:%.*]] = icmp sgt i8 [[X:%.*]], -228; CHECK-NEXT: call void @llvm.assume(i1 [[X_IS_NONNEGATIVE]])29; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[X]], -3230; CHECK-NEXT: ret i8 [[DIV]]31;32 %x_is_nonnegative = icmp sge i8 %x, -1 ; could be negative33 call void @llvm.assume(i1 %x_is_nonnegative)34 %div = sdiv i8 %x, -3235 ret i8 %div36}37define i8 @n2(i8 %x, i8 %y) {38; CHECK-LABEL: @n2(39; CHECK-NEXT: [[X_IS_NONNEGATIVE:%.*]] = icmp sgt i8 [[X:%.*]], -140; CHECK-NEXT: call void @llvm.assume(i1 [[X_IS_NONNEGATIVE]])41; CHECK-NEXT: [[DIV:%.*]] = sdiv i8 [[X]], -3142; CHECK-NEXT: ret i8 [[DIV]]43;44 %x_is_nonnegative = icmp sge i8 %x, 045 call void @llvm.assume(i1 %x_is_nonnegative)46 %div = sdiv i8 %x, -31 ; not a negative power of two47 ret i8 %div48}49