From: David Bolvansky Date: Wed, 4 Sep 2019 17:37:06 +0000 (+0000) Subject: [NFC] Added tests for new fold X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=406960246525f987c8f200b5dbac86708d3c8107;p=llvm [NFC] Added tests for new fold git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@370941 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Transforms/InstCombine/sub-xor-or-neg-and.ll b/test/Transforms/InstCombine/sub-xor-or-neg-and.ll new file mode 100644 index 00000000000..bf98b9a5937 --- /dev/null +++ b/test/Transforms/InstCombine/sub-xor-or-neg-and.ll @@ -0,0 +1,120 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -instcombine -S < %s | FileCheck %s + +declare void @use(i32) + +define i32 @sub_to_and(i32 %x, i32 %y) { +; CHECK-LABEL: @sub_to_and( +; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]] +; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[XOR]], [[OR]] +; CHECK-NEXT: ret i32 [[SUB]] +; + %or = or i32 %x, %y + %xor = xor i32 %x, %y + %sub = sub i32 %xor, %or + ret i32 %sub +} + +define i32 @sub_to_and_extra_use_sub(i32 %x, i32 %y) { +; CHECK-LABEL: @sub_to_and_extra_use_sub( +; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]] +; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[XOR]], [[OR]] +; CHECK-NEXT: call void @use(i32 [[SUB]]) +; CHECK-NEXT: ret i32 [[SUB]] +; + %or = or i32 %x, %y + %xor = xor i32 %x, %y + %sub = sub i32 %xor, %or + call void @use(i32 %sub) + ret i32 %sub +} + +define i32 @sub_to_and_extra_use_and(i32 %x, i32 %y) { +; CHECK-LABEL: @sub_to_and_extra_use_and( +; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]] +; CHECK-NEXT: call void @use(i32 [[XOR]]) +; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[XOR]], [[OR]] +; CHECK-NEXT: ret i32 [[SUB]] +; + %or = or i32 %x, %y + %xor = xor i32 %x, %y + call void @use(i32 %xor) + %sub = sub i32 %xor, %or + ret i32 %sub +} + +define i32 @sub_to_and_extra_use_or(i32 %x, i32 %y) { +; CHECK-LABEL: @sub_to_and_extra_use_or( +; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: call void @use(i32 [[OR]]) +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]] +; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[XOR]], [[OR]] +; CHECK-NEXT: ret i32 [[SUB]] +; + %or = or i32 %x, %y + call void @use(i32 %or) + %xor = xor i32 %x, %y + %sub = sub i32 %xor, %or + ret i32 %sub +} + +define i32 @sub_to_and_or_commuted(i32 %x, i32 %y) { +; CHECK-LABEL: @sub_to_and_or_commuted( +; CHECK-NEXT: [[OR:%.*]] = or i32 [[Y:%.*]], [[X:%.*]] +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]] +; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[XOR]], [[OR]] +; CHECK-NEXT: ret i32 [[SUB]] +; + %or = or i32 %y, %x + %xor = xor i32 %x, %y + %sub = sub i32 %xor, %or + ret i32 %sub +} + +define i32 @sub_to_and_and_commuted(i32 %x, i32 %y) { +; CHECK-LABEL: @sub_to_and_and_commuted( +; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y]], [[X]] +; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[XOR]], [[OR]] +; CHECK-NEXT: ret i32 [[SUB]] +; + %or = or i32 %x, %y + %xor = xor i32 %y, %x + %sub = sub i32 %xor, %or + ret i32 %sub +} + +define <2 x i32> @sub_to_and_vec(<2 x i32> %x, <2 x i32> %y) { +; CHECK-LABEL: @sub_to_and_vec( +; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i32> [[Y]], [[X]] +; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> [[XOR]], [[OR]] +; CHECK-NEXT: ret <2 x i32> [[SUB]] +; + %or = or <2 x i32> %x, %y + %xor = xor <2 x i32> %y, %x + %sub = sub <2 x i32> %xor, %or + ret <2 x i32> %sub +} + +; Negative tests + +define i32 @sub_to_and_extra_use_and_or(i32 %x, i32 %y) { +; CHECK-LABEL: @sub_to_and_extra_use_and_or( +; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: call void @use(i32 [[OR]]) +; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]] +; CHECK-NEXT: call void @use(i32 [[XOR]]) +; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[XOR]], [[OR]] +; CHECK-NEXT: ret i32 [[SUB]] +; + %or = or i32 %x, %y + call void @use(i32 %or) + %xor = xor i32 %x, %y + call void @use(i32 %xor) + %sub = sub i32 %xor, %or + ret i32 %sub +}