llvm.org GIT mirror llvm / c17583a
[InstSimplify] allow and-of-icmps folds with vector splat constants git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282590 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 3 years ago
2 changed file(s) with 75 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
15171517 return getFalse(ITy);
15181518 }
15191519
1520 // FIXME: Use m_APInt to allow vector splat matches.
1521 ConstantInt *CI1, *CI2;
1522 if (!match(Op0, m_ICmp(Pred0, m_Add(m_Value(V), m_ConstantInt(CI1)),
1523 m_ConstantInt(CI2))))
1520 // (icmp (add V, C0), C1) & (icmp V, C0)
1521 if (!match(Op0, m_ICmp(Pred0, m_Add(m_Value(V), m_APInt(C0)), m_APInt(C1))))
15241522 return nullptr;
15251523
1526 if (!match(Op1, m_ICmp(Pred1, m_Specific(V), m_Specific(CI1))))
1524 if (!match(Op1, m_ICmp(Pred1, m_Specific(V), m_Value())))
15271525 return nullptr;
15281526
15291527 auto *AddInst = cast(Op0->getOperand(0));
1528 if (AddInst->getOperand(1) != Op1->getOperand(1))
1529 return nullptr;
1530
15301531 bool isNSW = AddInst->hasNoSignedWrap();
15311532 bool isNUW = AddInst->hasNoUnsignedWrap();
15321533
1533 const APInt &CI1V = CI1->getValue();
1534 const APInt &CI2V = CI2->getValue();
1535 const APInt Delta = CI2V - CI1V;
1536 if (CI1V.isStrictlyPositive()) {
1534 const APInt Delta = *C1 - *C0;
1535 if (C0->isStrictlyPositive()) {
15371536 if (Delta == 2) {
15381537 if (Pred0 == ICmpInst::ICMP_ULT && Pred1 == ICmpInst::ICMP_SGT)
15391538 return getFalse(ITy);
15471546 return getFalse(ITy);
15481547 }
15491548 }
1550 if (CI1V.getBoolValue() && isNUW) {
1549 if (C0->getBoolValue() && isNUW) {
15511550 if (Delta == 2)
15521551 if (Pred0 == ICmpInst::ICMP_ULT && Pred1 == ICmpInst::ICMP_UGT)
15531552 return getFalse(ITy);
4848 ret i1 %cmp
4949 }
5050
51 define <2 x i1> @and_of_icmps0_vec(<2 x i32> %b) {
52 ; CHECK-LABEL: @and_of_icmps0_vec(
53 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
54 ;
55 %1 = add <2 x i32> %b,
56 %2 = icmp ult <2 x i32> %1,
57 %cmp3 = icmp sgt <2 x i32> %b,
58 %cmp = and <2 x i1> %2, %cmp3
59 ret <2 x i1> %cmp
60 }
61
5162 define i1 @and_of_icmps1(i32 %b) {
5263 ; CHECK-LABEL: @and_of_icmps1(
5364 ; CHECK-NEXT: ret i1 false
5970 ret i1 %cmp
6071 }
6172
73 define <2 x i1> @and_of_icmps1_vec(<2 x i32> %b) {
74 ; CHECK-LABEL: @and_of_icmps1_vec(
75 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
76 ;
77 %1 = add nsw <2 x i32> %b,
78 %2 = icmp slt <2 x i32> %1,
79 %cmp3 = icmp sgt <2 x i32> %b,
80 %cmp = and <2 x i1> %2, %cmp3
81 ret <2 x i1> %cmp
82 }
83
6284 define i1 @and_of_icmps2(i32 %b) {
6385 ; CHECK-LABEL: @and_of_icmps2(
6486 ; CHECK-NEXT: ret i1 false
7092 ret i1 %cmp
7193 }
7294
95 define <2 x i1> @and_of_icmps2_vec(<2 x i32> %b) {
96 ; CHECK-LABEL: @and_of_icmps2_vec(
97 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
98 ;
99 %1 = add <2 x i32> %b,
100 %2 = icmp ule <2 x i32> %1,
101 %cmp3 = icmp sgt <2 x i32> %b,
102 %cmp = and <2 x i1> %2, %cmp3
103 ret <2 x i1> %cmp
104 }
105
73106 define i1 @and_of_icmps3(i32 %b) {
74107 ; CHECK-LABEL: @and_of_icmps3(
75108 ; CHECK-NEXT: ret i1 false
81114 ret i1 %cmp
82115 }
83116
117 define <2 x i1> @and_of_icmps3_vec(<2 x i32> %b) {
118 ; CHECK-LABEL: @and_of_icmps3_vec(
119 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
120 ;
121 %1 = add nsw <2 x i32> %b,
122 %2 = icmp sle <2 x i32> %1,
123 %cmp3 = icmp sgt <2 x i32> %b,
124 %cmp = and <2 x i1> %2, %cmp3
125 ret <2 x i1> %cmp
126 }
127
84128 define i1 @and_of_icmps4(i32 %b) {
85129 ; CHECK-LABEL: @and_of_icmps4(
86130 ; CHECK-NEXT: ret i1 false
92136 ret i1 %cmp
93137 }
94138
139 define <2 x i1> @and_of_icmps4_vec(<2 x i32> %b) {
140 ; CHECK-LABEL: @and_of_icmps4_vec(
141 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
142 ;
143 %1 = add nuw <2 x i32> %b,
144 %2 = icmp ult <2 x i32> %1,
145 %cmp3 = icmp ugt <2 x i32> %b,
146 %cmp = and <2 x i1> %2, %cmp3
147 ret <2 x i1> %cmp
148 }
149
95150 define i1 @and_of_icmps5(i32 %b) {
96151 ; CHECK-LABEL: @and_of_icmps5(
97152 ; CHECK-NEXT: ret i1 false
101156 %cmp3 = icmp ugt i32 %b, 2
102157 %cmp = and i1 %2, %cmp3
103158 ret i1 %cmp
159 }
160
161 define <2 x i1> @and_of_icmps5_vec(<2 x i32> %b) {
162 ; CHECK-LABEL: @and_of_icmps5_vec(
163 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
164 ;
165 %1 = add nuw <2 x i32> %b,
166 %2 = icmp ule <2 x i32> %1,
167 %cmp3 = icmp ugt <2 x i32> %b,
168 %cmp = and <2 x i1> %2, %cmp3
169 ret <2 x i1> %cmp
104170 }
105171
106172 define i1 @or_of_icmps0(i32 %b) {