Skip to content

Commit 06855d4

Browse files
fhahnmahesh-attarde
authored andcommitted
[VPlan] Set correct flags when creating and cloning VPWidenCastRecipe.
Make sure that we set the correct wrap flags when creating new VPWidenCastRecipes for truncs and preserve the flags from the recipe directly when cloning, to make sure they are not dropped. Fixes llvm#160396
1 parent ad90c0c commit 06855d4

File tree

4 files changed

+366
-10
lines changed

4 files changed

+366
-10
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,9 @@ class VPIRFlags {
705705
VPIRFlags(WrapFlagsTy WrapFlags)
706706
: OpType(OperationType::OverflowingBinOp), WrapFlags(WrapFlags) {}
707707

708+
VPIRFlags(TruncFlagsTy TruncFlags)
709+
: OpType(OperationType::Trunc), TruncFlags(TruncFlags) {}
710+
708711
VPIRFlags(FastMathFlags FMFs) : OpType(OperationType::FPMathOp), FMFs(FMFs) {}
709712

710713
VPIRFlags(DisjointFlagsTy DisjointFlags)
@@ -1494,21 +1497,22 @@ class VPWidenCastRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
14941497

14951498
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy,
14961499
const VPIRFlags &Flags = {},
1500+
const VPIRMetadata &Metadata = {},
14971501
DebugLoc DL = DebugLoc::getUnknown())
14981502
: VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, Flags, DL),
1499-
VPIRMetadata(), Opcode(Opcode), ResultTy(ResultTy) {
1503+
VPIRMetadata(Metadata), Opcode(Opcode), ResultTy(ResultTy) {
15001504
assert(flagsValidForOpcode(Opcode) &&
15011505
"Set flags not supported for the provided opcode");
15021506
}
15031507

15041508
~VPWidenCastRecipe() override = default;
15051509

15061510
VPWidenCastRecipe *clone() override {
1511+
auto *New = new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy, *this,
1512+
*this, getDebugLoc());
15071513
if (auto *UV = getUnderlyingValue())
1508-
return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy,
1509-
*cast<CastInst>(UV));
1510-
1511-
return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy);
1514+
New->setUnderlyingValue(UV);
1515+
return New;
15121516
}
15131517

15141518
VP_CLASSOF_IMPL(VPDef::VPWidenCastSC)

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,13 +2016,13 @@ bool VPIRFlags::flagsValidForOpcode(unsigned Opcode) const {
20162016
return Opcode == Instruction::FAdd || Opcode == Instruction::FMul ||
20172017
Opcode == Instruction::FSub || Opcode == Instruction::FNeg ||
20182018
Opcode == Instruction::FDiv || Opcode == Instruction::FRem ||
2019+
Opcode == Instruction::FPExt || Opcode == Instruction::FPTrunc ||
20192020
Opcode == Instruction::FCmp || Opcode == Instruction::Select ||
20202021
Opcode == VPInstruction::WideIVStep ||
20212022
Opcode == VPInstruction::ReductionStartVector ||
20222023
Opcode == VPInstruction::ComputeReductionResult;
20232024
case OperationType::NonNegOp:
2024-
return Opcode == Instruction::ZExt;
2025-
break;
2025+
return Opcode == Instruction::ZExt || Opcode == Instruction::UIToFP;
20262026
case OperationType::Cmp:
20272027
return Opcode == Instruction::FCmp || Opcode == Instruction::ICmp;
20282028
case OperationType::Other:

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,7 +2195,8 @@ void VPlanTransforms::truncateToMinimalBitwidths(
21952195
auto [ProcessedIter, IterIsEmpty] = ProcessedTruncs.try_emplace(Op);
21962196
VPWidenCastRecipe *NewOp =
21972197
IterIsEmpty
2198-
? new VPWidenCastRecipe(Instruction::Trunc, Op, NewResTy)
2198+
? new VPWidenCastRecipe(Instruction::Trunc, Op, NewResTy,
2199+
VPIRFlags::TruncFlagsTy(false, false))
21992200
: ProcessedIter->second;
22002201
R.setOperand(Idx, NewOp);
22012202
if (!IterIsEmpty)
@@ -3566,13 +3567,13 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
35663567
Mul, Ext0, Ext1, Ext)) {
35673568
auto *NewExt0 = new VPWidenCastRecipe(
35683569
Ext0->getOpcode(), Ext0->getOperand(0), Ext->getResultType(), *Ext0,
3569-
Ext0->getDebugLoc());
3570+
*Ext0, Ext0->getDebugLoc());
35703571
NewExt0->insertBefore(Ext0);
35713572

35723573
VPWidenCastRecipe *NewExt1 = NewExt0;
35733574
if (Ext0 != Ext1) {
35743575
NewExt1 = new VPWidenCastRecipe(Ext1->getOpcode(), Ext1->getOperand(0),
3575-
Ext->getResultType(), *Ext1,
3576+
Ext->getResultType(), *Ext1, *Ext1,
35763577
Ext1->getDebugLoc());
35773578
NewExt1->insertBefore(Ext1);
35783579
}

0 commit comments

Comments
 (0)