Skip to content

Commit d406c15

Browse files
committed
[VPlan] Use VPInstructionWithType for casts in VPlan0. (NFC)
Use VPInstructionWithType for casts in VPlan0, to enable additional analysis/transforms on VPlan0, and more accurate modeling in VPlan0.
1 parent 700b77b commit d406c15

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8157,9 +8157,10 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(VPSingleDefRecipe *R,
81578157
return new VPWidenSelectRecipe(*cast<SelectInst>(Instr), R->operands());
81588158

81598159
if (Instruction::isCast(VPI->getOpcode())) {
8160+
auto *CastR = cast<VPInstructionWithType>(R);
81608161
auto *CI = cast<CastInst>(Instr);
81618162
return new VPWidenCastRecipe(CI->getOpcode(), VPI->getOperand(0),
8162-
CI->getType(), *CI);
8163+
CastR->getResultType(), *CI);
81638164
}
81648165

81658166
return tryToWiden(VPI);

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/Analysis/LoopInfo.h"
2121
#include "llvm/Analysis/LoopIterator.h"
2222
#include "llvm/Analysis/ScalarEvolution.h"
23+
#include "llvm/IR/InstrTypes.h"
2324
#include "llvm/IR/MDBuilder.h"
2425

2526
#define DEBUG_TYPE "vplan"
@@ -233,10 +234,15 @@ void PlainCFGBuilder::createVPInstructionsForVPBB(VPBasicBlock *VPBB,
233234
for (Value *Op : Inst->operands())
234235
VPOperands.push_back(getOrCreateVPOperand(Op));
235236

236-
// Build VPInstruction for any arbitrary Instruction without specific
237-
// representation in VPlan.
238-
NewR = cast<VPInstruction>(
239-
VPIRBuilder.createNaryOp(Inst->getOpcode(), VPOperands, Inst));
237+
if (auto *CI = dyn_cast<CastInst>(Inst)) {
238+
NewR = VPIRBuilder.createScalarCast(CI->getOpcode(), VPOperands[0],
239+
CI->getType(), CI->getDebugLoc());
240+
NewR->setUnderlyingValue(CI);
241+
} else {
242+
// Build VPInstruction for any arbitrary Instruction without specific
243+
// representation in VPlan.
244+
NewR = VPIRBuilder.createNaryOp(Inst->getOpcode(), VPOperands, Inst);
245+
}
240246
}
241247

242248
IRDef2VPValue[Inst] = NewR;

0 commit comments

Comments
 (0)