llvm.org GIT mirror llvm / cf8ba84
[InstCombine] clean up foldVectorBinop(); NFC 1. Fix include ordering. 2. Improve variable name (width is bitwidth not number-of-elements). 3. Add local Opcode variable to reduce code duplication. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343694 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 1 year, 9 months ago
1 changed file(s) with 12 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
5656 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
5757 #include "llvm/Analysis/TargetFolder.h"
5858 #include "llvm/Analysis/TargetLibraryInfo.h"
59 #include "llvm/Transforms/Utils/Local.h"
6059 #include "llvm/Analysis/ValueTracking.h"
6160 #include "llvm/IR/BasicBlock.h"
6261 #include "llvm/IR/CFG.h"
9695 #include "llvm/Support/raw_ostream.h"
9796 #include "llvm/Transforms/InstCombine/InstCombine.h"
9897 #include "llvm/Transforms/InstCombine/InstCombineWorklist.h"
98 #include "llvm/Transforms/Utils/Local.h"
9999 #include
100100 #include
101101 #include
13531353 Instruction *InstCombiner::foldVectorBinop(BinaryOperator &Inst) {
13541354 if (!Inst.getType()->isVectorTy()) return nullptr;
13551355
1356 unsigned VWidth = cast(Inst.getType())->getNumElements();
1356 BinaryOperator::BinaryOps Opcode = Inst.getOpcode();
1357 unsigned NumElts = cast(Inst.getType())->getNumElements();
13571358 Value *LHS = Inst.getOperand(0), *RHS = Inst.getOperand(1);
1358 assert(cast(LHS->getType())->getNumElements() == VWidth);
1359 assert(cast(RHS->getType())->getNumElements() == VWidth);
1359 assert(cast(LHS->getType())->getNumElements() == NumElts);
1360 assert(cast(RHS->getType())->getNumElements() == NumElts);
13601361
13611362 // If both operands of the binop are vector concatenations, then perform the
13621363 // narrow binop on each pair of the source operands followed by concatenation
13721373 // operating on exactly the same elements as the existing binop.
13731374 // TODO: We could ease the mask requirement to allow different undef lanes,
13741375 // but that requires an analysis of the binop-with-undef output value.
1375 Value *NewBO0 = Builder.CreateBinOp(Inst.getOpcode(), L0, R0);
1376 Value *NewBO0 = Builder.CreateBinOp(Opcode, L0, R0);
13761377 if (auto *BO = dyn_cast(NewBO0))
13771378 BO->copyIRFlags(&Inst);
1378 Value *NewBO1 = Builder.CreateBinOp(Inst.getOpcode(), L1, R1);
1379 Value *NewBO1 = Builder.CreateBinOp(Opcode, L1, R1);
13791380 if (auto *BO = dyn_cast(NewBO1))
13801381 BO->copyIRFlags(&Inst);
13811382 return new ShuffleVectorInst(NewBO0, NewBO1, Mask);
13881389 return nullptr;
13891390
13901391 auto createBinOpShuffle = [&](Value *X, Value *Y, Constant *M) {
1391 Value *XY = Builder.CreateBinOp(Inst.getOpcode(), X, Y);
1392 Value *XY = Builder.CreateBinOp(Opcode, X, Y);
13921393 if (auto *BO = dyn_cast(XY))
13931394 BO->copyIRFlags(&Inst);
13941395 return new ShuffleVectorInst(XY, UndefValue::get(XY->getType()), M);
14141415 if (match(&Inst, m_c_BinOp(
14151416 m_OneUse(m_ShuffleVector(m_Value(V1), m_Undef(), m_Constant(Mask))),
14161417 m_Constant(C))) &&
1417 V1->getType()->getVectorNumElements() <= VWidth) {
1418 V1->getType()->getVectorNumElements() <= NumElts) {
14181419 assert(Inst.getType()->getScalarType() == V1->getType()->getScalarType() &&
14191420 "Shuffle should not change scalar type");
14201421 unsigned V1Width = V1->getType()->getVectorNumElements();
14281429 SmallVector
14291430 NewVecC(V1Width, UndefValue::get(C->getType()->getScalarType()));
14301431 bool MayChange = true;
1431 for (unsigned I = 0; I < VWidth; ++I) {
1432 for (unsigned I = 0; I < NumElts; ++I) {
14321433 if (ShMask[I] >= 0) {
1433 assert(ShMask[I] < (int)VWidth && "Not expecting narrowing shuffle");
1434 assert(ShMask[I] < (int)NumElts && "Not expecting narrowing shuffle");
14341435 Constant *CElt = C->getAggregateElement(I);
14351436 Constant *NewCElt = NewVecC[ShMask[I]];
14361437 // Bail out if:
14541455 // that did not exist in the original code.
14551456 bool ConstOp1 = isa(Inst.getOperand(1));
14561457 if (Inst.isIntDivRem() || (Inst.isShift() && ConstOp1))
1457 NewC = getSafeVectorConstantForBinop(Inst.getOpcode(), NewC, ConstOp1);
1458 NewC = getSafeVectorConstantForBinop(Opcode, NewC, ConstOp1);
14581459
14591460 // Op(shuffle(V1, Mask), C) -> shuffle(Op(V1, NewC), Mask)
14601461 // Op(C, shuffle(V1, Mask)) -> shuffle(Op(NewC, V1), Mask)