@@ -292,14 +292,15 @@ Instruction *InstCombiner::foldSelectOpOp(SelectInst &SI, Instruction *TI,
292
292
return nullptr ;
293
293
294
294
// If this is a cast from the same type, merge.
295
+ Value *Cond = SI.getCondition ();
296
+ Type *CondTy = Cond->getType ();
295
297
if (TI->getNumOperands () == 1 && TI->isCast ()) {
296
298
Type *FIOpndTy = FI->getOperand (0 )->getType ();
297
299
if (TI->getOperand (0 )->getType () != FIOpndTy)
298
300
return nullptr ;
299
301
300
302
// The select condition may be a vector. We may only change the operand
301
303
// type if the vector width remains the same (and matches the condition).
302
- Type *CondTy = SI.getCondition ()->getType ();
303
304
if (CondTy->isVectorTy ()) {
304
305
if (!FIOpndTy->isVectorTy ())
305
306
return nullptr ;
@@ -326,8 +327,8 @@ Instruction *InstCombiner::foldSelectOpOp(SelectInst &SI, Instruction *TI,
326
327
327
328
// Fold this by inserting a select from the input values.
328
329
Value *NewSI =
329
- Builder.CreateSelect (SI. getCondition ( ), TI ->getOperand (0 ),
330
- FI-> getOperand ( 0 ), SI.getName () + " .v" , &SI);
330
+ Builder.CreateSelect (Cond, TI-> getOperand ( 0 ), FI ->getOperand (0 ),
331
+ SI.getName () + " .v" , &SI);
331
332
return CastInst::Create (Instruction::CastOps (TI->getOpcode ()), NewSI,
332
333
TI->getType ());
333
334
}
@@ -373,13 +374,12 @@ Instruction *InstCombiner::foldSelectOpOp(SelectInst &SI, Instruction *TI,
373
374
// If the select condition is a vector, the operands of the original select's
374
375
// operands also must be vectors. This may not be the case for getelementptr
375
376
// for example.
376
- if (SI.getCondition ()->getType ()->isVectorTy () &&
377
- (!OtherOpT->getType ()->isVectorTy () ||
378
- !OtherOpF->getType ()->isVectorTy ()))
377
+ if (CondTy->isVectorTy () && (!OtherOpT->getType ()->isVectorTy () ||
378
+ !OtherOpF->getType ()->isVectorTy ()))
379
379
return nullptr ;
380
380
381
381
// If we reach here, they do have operations in common.
382
- Value *NewSI = Builder.CreateSelect (SI. getCondition () , OtherOpT, OtherOpF,
382
+ Value *NewSI = Builder.CreateSelect (Cond , OtherOpT, OtherOpF,
383
383
SI.getName () + " .v" , &SI);
384
384
Value *Op0 = MatchIsOpZero ? MatchOp : NewSI;
385
385
Value *Op1 = MatchIsOpZero ? NewSI : MatchOp;
0 commit comments