@@ -299,6 +299,11 @@ Instruction *InstCombiner::visitSelectInstWithICmp(SelectInst &SI,
299
299
case ICmpInst::ICMP_SLT:
300
300
case ICmpInst::ICMP_UGT:
301
301
case ICmpInst::ICMP_SGT: {
302
+ // These transformations only work for selects over integers.
303
+ const IntegerType *SelectTy = dyn_cast<IntegerType>(SI.getType ());
304
+ if (!SelectTy)
305
+ break ;
306
+
302
307
Constant *AdjustedRHS;
303
308
if (Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_SGT)
304
309
AdjustedRHS = ConstantInt::get (CI->getContext (), CI->getValue () + 1 );
@@ -315,9 +320,8 @@ Instruction *InstCombiner::visitSelectInstWithICmp(SelectInst &SI,
315
320
// promote all to the larger type. This enables scalar evolution to
316
321
// analyze this expression.
317
322
else if (CmpRHS->getType ()->getScalarSizeInBits ()
318
- < SI.getType ()->getScalarSizeInBits ()) {
319
- Constant *sextRHS = ConstantExpr::getSExt (AdjustedRHS,
320
- SI.getType ());
323
+ < SelectTy->getBitWidth ()) {
324
+ Constant *sextRHS = ConstantExpr::getSExt (AdjustedRHS, SelectTy);
321
325
322
326
// X = sext x; x >s c ? X : C+1 --> X = sext x; X <s C+1 ? C+1 : X
323
327
// 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,
332
336
CmpLHS = FalseVal;
333
337
AdjustedRHS = sextRHS;
334
338
} else if (ICI->isUnsigned ()) {
335
- Constant *zextRHS = ConstantExpr::getZExt (AdjustedRHS,
336
- SI.getType ());
339
+ Constant *zextRHS = ConstantExpr::getZExt (AdjustedRHS, SelectTy);
337
340
// X = zext x; x >u c ? X : C+1 --> X = zext x; X <u C+1 ? C+1 : X
338
341
// X = zext x; x <u c ? X : C-1 --> X = zext x; X >u C-1 ? C-1 : X
339
342
// zext + signed compare cannot be changed:
0 commit comments