diff options
author | Frits van Bommel <fvbommel@gmail.com> | 2011-01-08 10:51:36 +0000 |
---|---|---|
committer | Frits van Bommel <fvbommel@gmail.com> | 2011-01-08 10:51:36 +0000 |
commit | 6a1fb8f2355206665264fa6f8c7de34b71ed2f28 (patch) | |
tree | e894f0597e84b3b36b93a00df39f6af276f71101 | |
parent | 8c5defd0b0efbfeb62ff8406af6483a6f36b5981 (diff) | |
download | bcm5719-llvm-6a1fb8f2355206665264fa6f8c7de34b71ed2f28.tar.gz bcm5719-llvm-6a1fb8f2355206665264fa6f8c7de34b71ed2f28.zip |
Fix a bug in r123034 (trying to sext/zext non-integers) and clean up a little.
llvm-svn: 123061
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 13 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/crash.ll | 6 |
2 files changed, 14 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index c2caedfa6c8..71a286ef69c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -299,6 +299,11 @@ Instruction *InstCombiner::visitSelectInstWithICmp(SelectInst &SI, case ICmpInst::ICMP_SLT: case ICmpInst::ICMP_UGT: case ICmpInst::ICMP_SGT: { + // These transformations only work for selects over integers. + const IntegerType *SelectTy = dyn_cast<IntegerType>(SI.getType()); + if (!SelectTy) + break; + Constant *AdjustedRHS; if (Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_SGT) AdjustedRHS = ConstantInt::get(CI->getContext(), CI->getValue() + 1); @@ -315,9 +320,8 @@ Instruction *InstCombiner::visitSelectInstWithICmp(SelectInst &SI, // promote all to the larger type. This enables scalar evolution to // analyze this expression. else if (CmpRHS->getType()->getScalarSizeInBits() - < SI.getType()->getScalarSizeInBits()) { - Constant *sextRHS = ConstantExpr::getSExt(AdjustedRHS, - SI.getType()); + < 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 @@ -332,8 +336,7 @@ Instruction *InstCombiner::visitSelectInstWithICmp(SelectInst &SI, CmpLHS = FalseVal; AdjustedRHS = sextRHS; } else if (ICI->isUnsigned()) { - Constant *zextRHS = ConstantExpr::getZExt(AdjustedRHS, - SI.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: diff --git a/llvm/test/Transforms/InstCombine/crash.ll b/llvm/test/Transforms/InstCombine/crash.ll index 60cb7477879..e87a30254e6 100644 --- a/llvm/test/Transforms/InstCombine/crash.ll +++ b/llvm/test/Transforms/InstCombine/crash.ll @@ -335,3 +335,9 @@ ret void declare i32 @func_14() + +define double @test16(i32 %a) nounwind { + %cmp = icmp slt i32 %a, 2 + %select = select i1 %cmp, double 2.000000e+00, double 3.141592e+00 + ret double %select +} |