Index: llvm/test/Transforms/InstCombine/icmp-shl-1-overflow.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/InstCombine/icmp-shl-1-overflow.ll @@ -0,0 +1,186 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -passes=instcombine -S | FileCheck %s + +declare void @use16(i16) +declare void @usev4(<4 x i4>) + +define i1 @icmp_shl_ugt_1(i8 %x) { +; CHECK-LABEL: @icmp_shl_ugt_1( +; CHECK-NEXT: [[ADD:%.*]] = shl i8 [[X:%.*]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[ADD]], [[X]] +; CHECK-NEXT: ret i1 [[CMP]] +; + %add = shl i8 %x, 1 + %cmp = icmp ugt i8 %add, %x + ret i1 %cmp +} + +define <2 x i1> @icmp_shl_ugt_2(<2 x i32> %_x) { +; CHECK-LABEL: @icmp_shl_ugt_2( +; CHECK-NEXT: [[X:%.*]] = add <2 x i32> [[_X:%.*]], +; CHECK-NEXT: [[ADD:%.*]] = shl <2 x i32> [[X]], +; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i32> [[X]], [[ADD]] +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %x = add <2 x i32> , %_x ; thwart complexity-based canonicalization + %add = shl <2 x i32> %x, + %cmp = icmp ugt <2 x i32> %x, %add + ret <2 x i1> %cmp +} + +define <3 x i1> @icmp_shl_uge_1(<3 x i7> %x) { +; CHECK-LABEL: @icmp_shl_uge_1( +; CHECK-NEXT: [[ADD:%.*]] = shl <3 x i7> [[X:%.*]], +; CHECK-NEXT: [[CMP:%.*]] = icmp uge <3 x i7> [[ADD]], [[X]] +; CHECK-NEXT: ret <3 x i1> [[CMP]] +; + %add = shl <3 x i7> %x, + %cmp = icmp uge <3 x i7> %add, %x + ret <3 x i1> %cmp +} + +define i1 @icmp_shl_uge_2(i5 %_x) { +; CHECK-LABEL: @icmp_shl_uge_2( +; CHECK-NEXT: [[X:%.*]] = add i5 [[_X:%.*]], 10 +; CHECK-NEXT: [[ADD:%.*]] = shl i5 [[X]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp uge i5 [[X]], [[ADD]] +; CHECK-NEXT: ret i1 [[CMP]] +; + %x = add i5 42, %_x ; thwart complexity-based canonicalization + %add = shl i5 %x, 1 + %cmp = icmp uge i5 %x, %add + ret i1 %cmp +} + +define i1 @icmp_shl_ult_1(i16 %x) { +; CHECK-LABEL: @icmp_shl_ult_1( +; CHECK-NEXT: [[ADD:%.*]] = shl i16 [[X:%.*]], 1 +; CHECK-NEXT: call void @use16(i16 [[ADD]]) +; CHECK-NEXT: [[CMP:%.*]] = icmp ult i16 [[ADD]], [[X]] +; CHECK-NEXT: ret i1 [[CMP]] +; + %add = shl i16 %x, 1 + call void @use16(i16 %add) ; extra use of shl + %cmp = icmp ult i16 %add, %x + ret i1 %cmp +} + +define <4 x i1> @icmp_shl_ult_2(<4 x i4> %_x) { +; CHECK-LABEL: @icmp_shl_ult_2( +; CHECK-NEXT: [[X:%.*]] = add <4 x i4> [[_X:%.*]], +; CHECK-NEXT: [[ADD:%.*]] = shl <4 x i4> [[X]], +; CHECK-NEXT: call void @usev4(<4 x i4> [[ADD]]) +; CHECK-NEXT: [[CMP:%.*]] = icmp ult <4 x i4> [[X]], [[ADD]] +; CHECK-NEXT: ret <4 x i1> [[CMP]] +; + %x = add <4 x i4> , %_x ; thwart complexity-based canonicalization + %add = shl <4 x i4> %x, + call void @usev4(<4 x i4> %add) ; extra use of shl + %cmp = icmp ult <4 x i4> %x, %add + ret <4 x i1> %cmp +} + +define <2 x i1> @icmp_shl_ule_1(<2 x i8> %x) { +; CHECK-LABEL: @icmp_shl_ule_1( +; CHECK-NEXT: [[ADD:%.*]] = shl <2 x i8> [[X:%.*]], +; CHECK-NEXT: [[CMP:%.*]] = icmp ule <2 x i8> [[ADD]], [[X]] +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %add = shl <2 x i8> %x, + %cmp = icmp ule <2 x i8> %add, %x + ret <2 x i1> %cmp +} + +define i1 @icmp_shl_ule_2(i8 %_x) { +; CHECK-LABEL: @icmp_shl_ule_2( +; CHECK-NEXT: [[X:%.*]] = add i8 [[_X:%.*]], 42 +; CHECK-NEXT: [[ADD:%.*]] = shl i8 [[X]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp ule i8 [[X]], [[ADD]] +; CHECK-NEXT: ret i1 [[CMP]] +; + %x = add i8 42, %_x ; thwart complexity-based canonicalization + %add = shl i8 %x, 1 + %cmp = icmp ule i8 %x, %add + ret i1 %cmp +} + +define i1 @icmp_shl_eq_1(i8 %x) { +; CHECK-LABEL: @icmp_shl_eq_1( +; CHECK-NEXT: [[ADD:%.*]] = shl i8 [[X:%.*]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[ADD]], [[X]] +; CHECK-NEXT: ret i1 [[CMP]] +; + %add = shl i8 %x, 1 + %cmp = icmp eq i8 %add, %x + ret i1 %cmp +} + +define <2 x i1> @icmp_shl_eq_2(<2 x i8> %_x) { +; CHECK-LABEL: @icmp_shl_eq_2( +; CHECK-NEXT: [[X:%.*]] = add <2 x i8> [[_X:%.*]], +; CHECK-NEXT: [[ADD:%.*]] = shl <2 x i8> [[X]], +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[X]], [[ADD]] +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %x = add <2 x i8> , %_x ; thwart complexity-based canonicalization + %add = shl <2 x i8> %x, + %cmp = icmp eq <2 x i8> %x, %add + ret <2 x i1> %cmp +} + +define <2 x i1> @icmp_shl_ne_1(<2 x i8> %x) { +; CHECK-LABEL: @icmp_shl_ne_1( +; CHECK-NEXT: [[ADD:%.*]] = shl <2 x i8> [[X:%.*]], +; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[ADD]], [[X]] +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %add = shl <2 x i8> %x, + %cmp = icmp ne <2 x i8> %add, %x + ret <2 x i1> %cmp +} + +define i1 @icmp_shl_ne_2(i8 %_x) { +; CHECK-LABEL: @icmp_shl_ne_2( +; CHECK-NEXT: [[X:%.*]] = add i8 [[_X:%.*]], 42 +; CHECK-NEXT: [[ADD:%.*]] = shl i8 [[X]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X]], [[ADD]] +; CHECK-NEXT: ret i1 [[CMP]] +; + %x = add i8 42, %_x ; thwart complexity-based canonicalization + %add = shl i8 %x, 1 + %cmp = icmp ne i8 %x, %add + ret i1 %cmp +} + +define i1 @negative_test_signed_pred(i8 %x) { +; CHECK-LABEL: @negative_test_signed_pred( +; CHECK-NEXT: [[ADD:%.*]] = shl i8 [[X:%.*]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[ADD]], [[X]] +; CHECK-NEXT: ret i1 [[CMP]] +; + %add = shl i8 %x, 1 + %cmp = icmp slt i8 %add, %x + ret i1 %cmp +} + +define i1 @negative_test_shl_more_than_1(i16 %x) { +; CHECK-LABEL: @negative_test_shl_more_than_1( +; CHECK-NEXT: [[ADD:%.*]] = shl i16 [[X:%.*]], 2 +; CHECK-NEXT: [[CMP:%.*]] = icmp ult i16 [[ADD]], [[X]] +; CHECK-NEXT: ret i1 [[CMP]] +; + %add = shl i16 %x, 2 + %cmp = icmp ult i16 %add, %x + ret i1 %cmp +} + +define i1 @negative_test_compare_with_different_value(i16 %x, i16 %y) { +; CHECK-LABEL: @negative_test_compare_with_different_value( +; CHECK-NEXT: [[ADD:%.*]] = shl i16 [[X:%.*]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp ult i16 [[ADD]], [[Y:%.*]] +; CHECK-NEXT: ret i1 [[CMP]] +; + %add = shl i16 %x, 1 + %cmp = icmp ult i16 %add, %y + ret i1 %cmp +}