diff options
author | Greg Bedwell <greg_bedwell@sn.scee.net> | 2016-11-02 23:17:05 +0000 |
---|---|---|
committer | Greg Bedwell <greg_bedwell@sn.scee.net> | 2016-11-02 23:17:05 +0000 |
commit | 5fc6f9459190fa1c9cb5e117c74aee45c80703ed (patch) | |
tree | 773f9261f1a3efd8d84d13dffee94e3aca8e16cd /llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | |
parent | 1f368434f0dd2af95f38b375c58c9b9fa7d9235f (diff) | |
download | bcm5719-llvm-5fc6f9459190fa1c9cb5e117c74aee45c80703ed.tar.gz bcm5719-llvm-5fc6f9459190fa1c9cb5e117c74aee45c80703ed.zip |
Revert "[InstCombine] allow splat vector folds in adjustMinMax()"
This reverts commit r285732.
This change introduced a new assertion failure in the following
testcase at -O2:
typedef short __v8hi __attribute__((__vector_size__(16)));
__v8hi foo(__v8hi &V1, __v8hi &V2, unsigned mask) {
__v8hi Result = V1;
if (mask & 0x80)
Result[0] = V2[0];
return Result;
}
llvm-svn: 285866
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 03fc1a09edc..cfae47fbd7e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -424,20 +424,24 @@ static bool adjustMinMax(SelectInst &Sel, ICmpInst &Cmp) { Value *FalseVal = Sel.getFalseValue(); // We may move or edit the compare, so make sure the select is the only user. - const APInt *CmpC; - if (!Cmp.hasOneUse() || !match(CmpRHS, m_APInt(CmpC))) + if (!Cmp.hasOneUse()) return false; - // These transforms only work for selects of integers or vector integers. - auto *SelEltTy = dyn_cast<IntegerType>(Sel.getType()->getScalarType()); - if (!SelEltTy) + // FIXME: Use m_APInt to allow vector folds. + auto *CI = dyn_cast<ConstantInt>(CmpRHS); + if (!CI) + return false; + + // These transformations only work for selects over integers. + IntegerType *SelectTy = dyn_cast<IntegerType>(Sel.getType()); + if (!SelectTy) return false; Constant *AdjustedRHS; if (Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_SGT) - AdjustedRHS = ConstantInt::get(CmpRHS->getType(), *CmpC + 1); + AdjustedRHS = ConstantInt::get(CI->getContext(), CI->getValue() + 1); else if (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_SLT) - AdjustedRHS = ConstantInt::get(CmpRHS->getType(), *CmpC - 1); + AdjustedRHS = ConstantInt::get(CI->getContext(), CI->getValue() - 1); else return false; @@ -450,8 +454,8 @@ static bool adjustMinMax(SelectInst &Sel, ICmpInst &Cmp) { // Types do not match. Instead of calculating this with mixed types, promote // all to the larger type. This enables scalar evolution to analyze this // expression. - else if (CmpRHS->getType()->getScalarSizeInBits() < SelEltTy->getBitWidth()) { - Constant *SextRHS = ConstantExpr::getSExt(AdjustedRHS, Sel.getType()); + else if (CmpRHS->getType()->getScalarSizeInBits() < SelectTy->getBitWidth()) { + Constant *SextRHS = ConstantExpr::getSExt(AdjustedRHS, SelectTy); // X = sext x; x >s c ? X : C+1 --> X = sext x; X <s C+1 ? C+1 : X // X = sext x; x <s c ? X : C-1 --> X = sext x; X >s C-1 ? C-1 : X @@ -465,7 +469,7 @@ static bool adjustMinMax(SelectInst &Sel, ICmpInst &Cmp) { CmpLHS = FalseVal; AdjustedRHS = SextRHS; } else if (Cmp.isUnsigned()) { - Constant *ZextRHS = ConstantExpr::getZExt(AdjustedRHS, Sel.getType()); + Constant *ZextRHS = ConstantExpr::getZExt(AdjustedRHS, SelectTy); // X = zext x; x >u c ? X : C+1 --> X = zext x; X <u C+1 ? C+1 : X // X = zext x; x <u c ? X : C-1 --> X = zext x; X >u C-1 ? C-1 : X // zext + signed compare cannot be changed: |