[llvm-commits] [llvm] r123061 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineSelect.cpp test/Transforms/InstCombine/crash.ll
Frits van Bommel
fvbommel at gmail.com
Sat Jan 8 02:51:37 PST 2011
Author: fvbommel
Date: Sat Jan 8 04:51:36 2011
New Revision: 123061
URL: http://llvm.org/viewvc/llvm-project?rev=123061&view=rev
Log:
Fix a bug in r123034 (trying to sext/zext non-integers) and clean up a little.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/trunk/test/Transforms/InstCombine/crash.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp?rev=123061&r1=123060&r2=123061&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp Sat Jan 8 04:51:36 2011
@@ -299,6 +299,11 @@
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 @@
// 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 @@
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:
Modified: llvm/trunk/test/Transforms/InstCombine/crash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/crash.ll?rev=123061&r1=123060&r2=123061&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/crash.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/crash.ll Sat Jan 8 04:51:36 2011
@@ -335,3 +335,9 @@
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
+}
More information about the llvm-commits
mailing list