From 1194a001b6d755b7e5c61b160652c1877813dc2e Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 6 Apr 2017 05:28:41 +0000 Subject: [PATCH] [InstSimplify] Teach SimplifyAddInst and SimplifySubInst that vectors of i1 can be treated as Xor too. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299626 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/InstructionSimplify.cpp | 4 +-- test/Transforms/InstSimplify/addsub.ll | 36 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 test/Transforms/InstSimplify/addsub.ll diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index 5cb93df7395..85fcbcccb2c 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -579,7 +579,7 @@ static Value *SimplifyAddInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW, return Y; /// i1 add -> xor. - if (MaxRecurse && Op0->getType()->isIntegerTy(1)) + if (MaxRecurse && Op0->getType()->getScalarType()->isIntegerTy(1)) if (Value *V = SimplifyXorInst(Op0, Op1, Q, MaxRecurse-1)) return V; @@ -796,7 +796,7 @@ static Value *SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW, return ConstantExpr::getIntegerCast(Result, Op0->getType(), true); // i1 sub -> xor. - if (MaxRecurse && Op0->getType()->isIntegerTy(1)) + if (MaxRecurse && Op0->getType()->getScalarType()->isIntegerTy(1)) if (Value *V = SimplifyXorInst(Op0, Op1, Q, MaxRecurse-1)) return V; diff --git a/test/Transforms/InstSimplify/addsub.ll b/test/Transforms/InstSimplify/addsub.ll new file mode 100644 index 00000000000..5ba13477b20 --- /dev/null +++ b/test/Transforms/InstSimplify/addsub.ll @@ -0,0 +1,36 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -instsimplify -S | FileCheck %s + +define i1 @test1(i1 %a) { +; CHECK-LABEL: @test1( +; CHECK-NEXT: ret i1 true +; + %b = xor i1 %a, true + %res = sub i1 %a, %b + ret i1 %res +} + +define <2 x i1> @test2(<2 x i1> %a) { +; CHECK-LABEL: @test2( +; CHECK-NEXT: ret <2 x i1> +; + %b = xor <2 x i1> %a, + %res = sub <2 x i1> %a, %b + ret <2 x i1> %res +} + +define i1 @test5(i1 %a) { +; CHECK-LABEL: @test5( +; CHECK-NEXT: ret i1 false +; + %res = add i1 %a, %a + ret i1 %res +} + +define <2 x i1> @test6(<2 x i1> %a) { +; CHECK-LABEL: @test6( +; CHECK-NEXT: ret <2 x i1> zeroinitializer +; + %res = add <2 x i1> %a, %a + ret <2 x i1> %res +}