Index: llvm/test/Transforms/InstCombine/icmp-not.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/InstCombine/icmp-not.ll @@ -0,0 +1,125 @@ +; 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 <2 x i1> @icmp_not_sgt(<2 x i32> %_x) { +; CHECK-LABEL: @icmp_not_sgt( +; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i32> , [[_X:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i32> [[X]], +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[X]], [[NOT]] +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %x = sdiv <2 x i32> , %_x ; thwart complexity-based canonicalization + %not = xor <2 x i32> %x, + %cmp = icmp sgt <2 x i32> %x, %not + ret <2 x i1> %cmp +} + +define i1 @icmp_not_sgt_swapped(i8 %x) { +; CHECK-LABEL: @icmp_not_sgt_swapped( +; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1 +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[NOT]], [[X]] +; CHECK-NEXT: ret i1 [[CMP]] +; + %not = xor i8 %x, -1 + %cmp = icmp sgt i8 %not, %x + ret i1 %cmp +} + +define i1 @icmp__not_sge(i5 %_x) { +; CHECK-LABEL: @icmp__not_sge( +; CHECK-NEXT: [[X:%.*]] = sdiv i5 10, [[_X:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor i5 [[X]], -1 +; CHECK-NEXT: [[CMP:%.*]] = icmp sge i5 [[X]], [[NOT]] +; CHECK-NEXT: ret i1 [[CMP]] +; + %x = sdiv i5 42, %_x ; thwart complexity-based canonicalization + %not = xor i5 %x, -1 + %cmp = icmp sge i5 %x, %not + ret i1 %cmp +} + +define <3 x i1> @icmp_not_sge_swapped(<3 x i7> %x) { +; CHECK-LABEL: @icmp_not_sge_swapped( +; CHECK-NEXT: [[NOT:%.*]] = xor <3 x i7> [[X:%.*]], +; CHECK-NEXT: [[CMP:%.*]] = icmp sge <3 x i7> [[NOT]], [[X]] +; CHECK-NEXT: ret <3 x i1> [[CMP]] +; + %not = xor <3 x i7> %x, + %cmp = icmp sge <3 x i7> %not, %x + ret <3 x i1> %cmp +} + +define <4 x i1> @icmp_not_slt(<4 x i4> %_x) { +; CHECK-LABEL: @icmp_not_slt( +; CHECK-NEXT: [[X:%.*]] = sdiv <4 x i4> , [[_X:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor <4 x i4> [[X]], +; CHECK-NEXT: call void @usev4(<4 x i4> [[NOT]]) +; CHECK-NEXT: [[CMP:%.*]] = icmp slt <4 x i4> [[X]], [[NOT]] +; CHECK-NEXT: ret <4 x i1> [[CMP]] +; + %x = sdiv <4 x i4> , %_x ; thwart complexity-based canonicalization + %not = xor <4 x i4> %x, + call void @usev4(<4 x i4> %not) ; extra use of xor + %cmp = icmp slt <4 x i4> %x, %not + ret <4 x i1> %cmp +} + +define i1 @icmp_not_slt_swapped(i16 %x) { +; CHECK-LABEL: @icmp_not_slt_swapped( +; CHECK-NEXT: [[NOT:%.*]] = xor i16 [[X:%.*]], -1 +; CHECK-NEXT: call void @use16(i16 [[NOT]]) +; CHECK-NEXT: [[CMP:%.*]] = icmp slt i16 [[NOT]], [[X]] +; CHECK-NEXT: ret i1 [[CMP]] +; + %not = xor i16 %x, -1 + call void @use16(i16 %not) ; extra use of xor + %cmp = icmp slt i16 %not, %x + ret i1 %cmp +} + +define i1 @icmp_not_sle(i8 %_x) { +; CHECK-LABEL: @icmp_not_sle( +; CHECK-NEXT: [[X:%.*]] = sdiv i8 42, [[_X:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X]], -1 +; CHECK-NEXT: [[CMP:%.*]] = icmp sle i8 [[X]], [[NOT]] +; CHECK-NEXT: ret i1 [[CMP]] +; + %x = sdiv i8 42, %_x ; thwart complexity-based canonicalization + %not = xor i8 %x, -1 + %cmp = icmp sle i8 %x, %not + ret i1 %cmp +} + +define <2 x i1> @icmp_not_sle_swapped(<2 x i8> %x) { +; CHECK-LABEL: @icmp_not_sle_swapped( +; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i8> [[X:%.*]], +; CHECK-NEXT: [[CMP:%.*]] = icmp sle <2 x i8> [[NOT]], [[X]] +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %not = xor <2 x i8> %x, + %cmp = icmp sle <2 x i8> %not, %x + ret <2 x i1> %cmp +} + +define i1 @negative_test_unsigned_pred(i8 %x) { +; CHECK-LABEL: @negative_test_unsigned_pred( +; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X:%.*]], -1 +; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[NOT]], [[X]] +; CHECK-NEXT: ret i1 [[CMP]] +; + %not = xor i8 %x, -1 + %cmp = icmp ugt i8 %not, %x + ret i1 %cmp +} + +define i1 @negative_test_equality(i8 %x) { +; CHECK-LABEL: @negative_test_equality( +; CHECK-NEXT: ret i1 false +; + %not = xor i8 %x, -1 + %cmp = icmp eq i8 %not, %x + ret i1 %cmp +}