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 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:%.*]], -1 15; CHECK-NEXT: call void @llvm.assume(i1 [[X_IS_NONNEGATIVE]]) 16; CHECK-NEXT: [[TMP1:%.*]] = lshr i8 [[X]], 5 17; CHECK-NEXT: [[DIV:%.*]] = sub nsw i8 0, [[TMP1]] 18; CHECK-NEXT: ret i8 [[DIV]] 19; 20 %x_is_nonnegative = icmp sge i8 %x, 0 21 call void @llvm.assume(i1 %x_is_nonnegative) 22 %div = sdiv i8 %x, -32 23 ret i8 %div 24} 25define i8 @n1(i8 %x, i8 %y) { 26; CHECK-LABEL: @n1( 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]] 31; 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 35 ret i8 %div 36} 37define i8 @n2(i8 %x, i8 %y) { 38; CHECK-LABEL: @n2( 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]] 43; 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 47 ret i8 %div 48} 49