llvm.org GIT mirror llvm / a9403e9
[InstCombine] enable vector select of bools -> logic folds git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274465 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 4 years ago
2 changed file(s) with 19 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
917917 SimplifySelectInst(CondVal, TrueVal, FalseVal, DL, TLI, DT, AC))
918918 return replaceInstUsesWith(SI, V);
919919
920 if (SI.getType()->isIntegerTy(1)) {
921 if (ConstantInt *C = dyn_cast(TrueVal)) {
922 if (C->getZExtValue()) {
920 if (SI.getType()->getScalarType()->isIntegerTy(1) &&
921 TrueVal->getType() == CondVal->getType()) {
922 const APInt *TrueC;
923 if (match(TrueVal, m_APInt(TrueC))) {
924 if (TrueC->isAllOnesValue()) {
923925 // Change: A = select B, true, C --> A = or B, C
924926 return BinaryOperator::CreateOr(CondVal, FalseVal);
925927 }
927929 Value *NotCond = Builder->CreateNot(CondVal, "not." + CondVal->getName());
928930 return BinaryOperator::CreateAnd(NotCond, FalseVal);
929931 }
930 if (ConstantInt *C = dyn_cast(FalseVal)) {
931 if (!C->getZExtValue()) {
932 const APInt *FalseC;
933 if (match(FalseVal, m_APInt(FalseC))) {
934 if (*FalseC == 0) {
932935 // Change: A = select B, C, false --> A = and B, C
933936 return BinaryOperator::CreateAnd(CondVal, TrueVal);
934937 }
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -instcombine -S | FileCheck %s
12
23 ; PR1822
6364
6465 define <2 x i1> @test7vec(<2 x i1> %C, <2 x i1> %X) {
6566 ; CHECK-LABEL: @test7vec(
66 ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> %C, <2 x i1> , <2 x i1> %X
67 ; CHECK-NEXT: [[R:%.*]] = or <2 x i1> %C, %X
6768 ; CHECK-NEXT: ret <2 x i1> [[R]]
6869 ;
6970 %R = select <2 x i1> %C, <2 x i1> , <2 x i1> %X
8182
8283 define <2 x i1> @test8vec(<2 x i1> %C, <2 x i1> %X) {
8384 ; CHECK-LABEL: @test8vec(
84 ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> %C, <2 x i1> %X, <2 x i1> zeroinitializer
85 ; CHECK-NEXT: [[R:%.*]] = and <2 x i1> %C, %X
8586 ; CHECK-NEXT: ret <2 x i1> [[R]]
8687 ;
8788 %R = select <2 x i1> %C, <2 x i1> %X, <2 x i1>
100101
101102 define <2 x i1> @test9vec(<2 x i1> %C, <2 x i1> %X) {
102103 ; CHECK-LABEL: @test9vec(
103 ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> %C, <2 x i1> zeroinitializer, <2 x i1> %X
104 ; CHECK-NEXT: [[NOT_C:%.*]] = xor <2 x i1> %C,
105 ; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[NOT_C]], %X
104106 ; CHECK-NEXT: ret <2 x i1> [[R]]
105107 ;
106108 %R = select <2 x i1> %C, <2 x i1> , <2 x i1> %X
119121
120122 define <2 x i1> @test10vec(<2 x i1> %C, <2 x i1> %X) {
121123 ; CHECK-LABEL: @test10vec(
122 ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> %C, <2 x i1> %X, <2 x i1>
124 ; CHECK-NEXT: [[NOT_C:%.*]] = xor <2 x i1> %C,
125 ; CHECK-NEXT: [[R:%.*]] = or <2 x i1> [[NOT_C]], %X
123126 ; CHECK-NEXT: ret <2 x i1> [[R]]
124127 ;
125128 %R = select <2 x i1> %C, <2 x i1> %X, <2 x i1>
137140
138141 define <2 x i1> @test23vec(<2 x i1> %a, <2 x i1> %b) {
139142 ; CHECK-LABEL: @test23vec(
140 ; CHECK-NEXT: [[C:%.*]] = select <2 x i1> %a, <2 x i1> %b, <2 x i1> %a
143 ; CHECK-NEXT: [[C:%.*]] = and <2 x i1> %a, %b
141144 ; CHECK-NEXT: ret <2 x i1> [[C]]
142145 ;
143146 %c = select <2 x i1> %a, <2 x i1> %b, <2 x i1> %a
155158
156159 define <2 x i1> @test24vec(<2 x i1> %a, <2 x i1> %b) {
157160 ; CHECK-LABEL: @test24vec(
158 ; CHECK-NEXT: [[C:%.*]] = select <2 x i1> %a, <2 x i1> %a, <2 x i1> %b
161 ; CHECK-NEXT: [[C:%.*]] = or <2 x i1> %a, %b
159162 ; CHECK-NEXT: ret <2 x i1> [[C]]
160163 ;
161164 %c = select <2 x i1> %a, <2 x i1> %a, <2 x i1> %b
176179 define <2 x i1> @test62vec(<2 x i1> %A, <2 x i1> %B) {
177180 ; CHECK-LABEL: @test62vec(
178181 ; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i1> %A,
179 ; CHECK-NEXT: [[C:%.*]] = select <2 x i1> %A, <2 x i1> [[NOT]], <2 x i1> %B
182 ; CHECK-NEXT: [[C:%.*]] = and <2 x i1> [[NOT]], %B
180183 ; CHECK-NEXT: ret <2 x i1> [[C]]
181184 ;
182185 %not = xor <2 x i1> %A,
198201 define <2 x i1> @test63vec(<2 x i1> %A, <2 x i1> %B) {
199202 ; CHECK-LABEL: @test63vec(
200203 ; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i1> %A,
201 ; CHECK-NEXT: [[C:%.*]] = select <2 x i1> %A, <2 x i1> %B, <2 x i1> [[NOT]]
204 ; CHECK-NEXT: [[C:%.*]] = or <2 x i1> %B, [[NOT]]
202205 ; CHECK-NEXT: ret <2 x i1> [[C]]
203206 ;
204207 %not = xor <2 x i1> %A,