llvm.org GIT mirror llvm / b0c3839
[InstCombine] Teach SimplifyDemandedVectorElts how to handle ConstantVector select masks with ConstantExpr elements (PR24922) If the mask of a select instruction is a ConstantVector, method SimplifyDemandedVectorElts iterates over the mask elements to identify which values are selected from the select inputs. Before this patch, method SimplifyDemandedVectorElts always used method Constant::isNullValue() to check if a value in the mask was zero. Unfortunately that method always returns false when called on a ConstantExpr. This patch fixes the problem in SimplifyDemandedVectorElts by adding an explicit check for ConstantExpr values. Now, if a value in the mask is a ConstantExpr, we avoid calling isNullValue() on it. Fixes PR24922. Differential Revision: http://reviews.llvm.org/D13219 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249390 91177308-0d34-0410-b5e6-96231b3b80d8 Andrea Di Biagio 4 years ago
2 changed file(s) with 20 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
10561056 APInt LeftDemanded(DemandedElts), RightDemanded(DemandedElts);
10571057 if (ConstantVector* CV = dyn_cast(I->getOperand(0))) {
10581058 for (unsigned i = 0; i < VWidth; i++) {
1059 if (CV->getAggregateElement(i)->isNullValue())
1059 Constant *CElt = CV->getAggregateElement(i);
1060 // Method isNullValue always returns false when called on a
1061 // ConstantExpr. If CElt is a ConstantExpr then skip it in order to
1062 // to avoid propagating incorrect information.
1063 if (isa(CElt))
1064 continue;
1065 if (CElt->isNullValue())
10601066 LeftDemanded.clearBit(i);
10611067 else
10621068 RightDemanded.clearBit(i);
252252 %a = tail call <4 x double> @llvm.x86.avx.vpermilvar.pd.256(<4 x double> %v, <4 x i64> zeroinitializer)
253253 ret <4 x double> %a
254254 }
255
256 define <2 x i64> @PR24922(<2 x i64> %v) {
257 ; CHECK-LABEL: @PR24922
258 ; CHECK: select <2 x i1>
259 ;
260 ; Check that instcombine doesn't wrongly fold the select statement into a
261 ; ret <2 x i64> %v
262 ;
263 ; FIXME: We should be able to simplify the ConstantExpr in the select mask.
264 entry:
265 %result = select <2 x i1> bitcast (<4 x i32> to <2 x i64>), i64 0), i64 0), i1 true>, <2 x i64> %v, <2 x i64> zeroinitializer
266 ret <2 x i64> %result
267 }