Skip to content

Commit f8e9cda

Browse files
committed
[InstCombine] reduce code duplication; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360059 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b671419 commit f8e9cda

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,15 @@ Instruction *InstCombiner::foldSelectOpOp(SelectInst &SI, Instruction *TI,
292292
return nullptr;
293293

294294
// If this is a cast from the same type, merge.
295+
Value *Cond = SI.getCondition();
296+
Type *CondTy = Cond->getType();
295297
if (TI->getNumOperands() == 1 && TI->isCast()) {
296298
Type *FIOpndTy = FI->getOperand(0)->getType();
297299
if (TI->getOperand(0)->getType() != FIOpndTy)
298300
return nullptr;
299301

300302
// The select condition may be a vector. We may only change the operand
301303
// type if the vector width remains the same (and matches the condition).
302-
Type *CondTy = SI.getCondition()->getType();
303304
if (CondTy->isVectorTy()) {
304305
if (!FIOpndTy->isVectorTy())
305306
return nullptr;
@@ -326,8 +327,8 @@ Instruction *InstCombiner::foldSelectOpOp(SelectInst &SI, Instruction *TI,
326327

327328
// Fold this by inserting a select from the input values.
328329
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);
331332
return CastInst::Create(Instruction::CastOps(TI->getOpcode()), NewSI,
332333
TI->getType());
333334
}
@@ -373,13 +374,12 @@ Instruction *InstCombiner::foldSelectOpOp(SelectInst &SI, Instruction *TI,
373374
// If the select condition is a vector, the operands of the original select's
374375
// operands also must be vectors. This may not be the case for getelementptr
375376
// 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()))
379379
return nullptr;
380380

381381
// 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,
383383
SI.getName() + ".v", &SI);
384384
Value *Op0 = MatchIsOpZero ? MatchOp : NewSI;
385385
Value *Op1 = MatchIsOpZero ? NewSI : MatchOp;

0 commit comments

Comments
 (0)