llvm.org GIT mirror llvm / f8e9cda
[InstCombine] reduce code duplication; NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360059 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 1 year, 5 months ago
1 changed file(s) with 7 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
291291 return nullptr;
292292
293293 // If this is a cast from the same type, merge.
294 Value *Cond = SI.getCondition();
295 Type *CondTy = Cond->getType();
294296 if (TI->getNumOperands() == 1 && TI->isCast()) {
295297 Type *FIOpndTy = FI->getOperand(0)->getType();
296298 if (TI->getOperand(0)->getType() != FIOpndTy)
298300
299301 // The select condition may be a vector. We may only change the operand
300302 // type if the vector width remains the same (and matches the condition).
301 Type *CondTy = SI.getCondition()->getType();
302303 if (CondTy->isVectorTy()) {
303304 if (!FIOpndTy->isVectorTy())
304305 return nullptr;
325326
326327 // Fold this by inserting a select from the input values.
327328 Value *NewSI =
328 Builder.CreateSelect(SI.getCondition(), TI->getOperand(0),
329 FI->getOperand(0), SI.getName() + ".v", &SI);
329 Builder.CreateSelect(Cond, TI->getOperand(0), FI->getOperand(0),
330 SI.getName() + ".v", &SI);
330331 return CastInst::Create(Instruction::CastOps(TI->getOpcode()), NewSI,
331332 TI->getType());
332333 }
372373 // If the select condition is a vector, the operands of the original select's
373374 // operands also must be vectors. This may not be the case for getelementptr
374375 // for example.
375 if (SI.getCondition()->getType()->isVectorTy() &&
376 (!OtherOpT->getType()->isVectorTy() ||
377 !OtherOpF->getType()->isVectorTy()))
376 if (CondTy->isVectorTy() && (!OtherOpT->getType()->isVectorTy() ||
377 !OtherOpF->getType()->isVectorTy()))
378378 return nullptr;
379379
380380 // If we reach here, they do have operations in common.
381 Value *NewSI = Builder.CreateSelect(SI.getCondition(), OtherOpT, OtherOpF,
381 Value *NewSI = Builder.CreateSelect(Cond, OtherOpT, OtherOpF,
382382 SI.getName() + ".v", &SI);
383383 Value *Op0 = MatchIsOpZero ? MatchOp : NewSI;
384384 Value *Op1 = MatchIsOpZero ? NewSI : MatchOp;