-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[VPlan] Make VPReductionRecipe a VPRecipeWithIRFlags. NFC #130881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
9a0e4d7
087a533
6be4c38
d60f933
07b5790
48454c6
36b40fc
0473b05
942a14d
abd65e9
e7d6f55
6c6ccb2
ad67b8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -2224,7 +2224,7 @@ void VPReductionRecipe::execute(VPTransformState &State) { | |||||||
| RecurKind Kind = RdxDesc.getRecurrenceKind(); | ||||||||
| // Propagate the fast-math flags carried by the underlying instruction. | ||||||||
| IRBuilderBase::FastMathFlagGuard FMFGuard(State.Builder); | ||||||||
| State.Builder.setFastMathFlags(RdxDesc.getFastMathFlags()); | ||||||||
| State.Builder.setFastMathFlags(getFastMathFlags()); | ||||||||
| State.setDebugLocFrom(getDebugLoc()); | ||||||||
| Value *NewVecOp = State.get(getVecOp()); | ||||||||
| if (VPValue *Cond = getCondOp()) { | ||||||||
|
|
@@ -2275,7 +2275,7 @@ void VPReductionEVLRecipe::execute(VPTransformState &State) { | |||||||
| // Propagate the fast-math flags carried by the underlying instruction. | ||||||||
| IRBuilderBase::FastMathFlagGuard FMFGuard(Builder); | ||||||||
| const RecurrenceDescriptor &RdxDesc = getRecurrenceDescriptor(); | ||||||||
| Builder.setFastMathFlags(RdxDesc.getFastMathFlags()); | ||||||||
| Builder.setFastMathFlags(getFastMathFlags()); | ||||||||
|
|
||||||||
| RecurKind Kind = RdxDesc.getRecurrenceKind(); | ||||||||
| Value *Prev = State.get(getChainOp(), /*IsScalar*/ true); | ||||||||
|
|
@@ -2312,6 +2312,7 @@ InstructionCost VPReductionRecipe::computeCost(ElementCount VF, | |||||||
| Type *ElementTy = Ctx.Types.inferScalarType(this); | ||||||||
| auto *VectorTy = cast<VectorType>(toVectorTy(ElementTy, VF)); | ||||||||
| unsigned Opcode = RdxDesc.getOpcode(); | ||||||||
| FastMathFlags FMFs = getFastMathFlags(); | ||||||||
|
|
||||||||
| // TODO: Support any-of and in-loop reductions. | ||||||||
| assert( | ||||||||
|
|
@@ -2331,12 +2332,12 @@ InstructionCost VPReductionRecipe::computeCost(ElementCount VF, | |||||||
| Ctx.TTI.getArithmeticInstrCost(Opcode, ElementTy, Ctx.CostKind); | ||||||||
| if (RecurrenceDescriptor::isMinMaxRecurrenceKind(RdxKind)) { | ||||||||
| Intrinsic::ID Id = getMinMaxReductionIntrinsicOp(RdxKind); | ||||||||
| return Cost + Ctx.TTI.getMinMaxReductionCost( | ||||||||
| Id, VectorTy, RdxDesc.getFastMathFlags(), Ctx.CostKind); | ||||||||
| return Cost + | ||||||||
| Ctx.TTI.getMinMaxReductionCost(Id, VectorTy, FMFs, Ctx.CostKind); | ||||||||
| } | ||||||||
|
|
||||||||
| return Cost + Ctx.TTI.getArithmeticReductionCost( | ||||||||
| Opcode, VectorTy, RdxDesc.getFastMathFlags(), Ctx.CostKind); | ||||||||
| return Cost + Ctx.TTI.getArithmeticReductionCost(Opcode, VectorTy, FMFs, | ||||||||
| Ctx.CostKind); | ||||||||
| } | ||||||||
|
|
||||||||
| #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) | ||||||||
|
|
@@ -2348,7 +2349,7 @@ void VPReductionRecipe::print(raw_ostream &O, const Twine &Indent, | |||||||
| getChainOp()->printAsOperand(O, SlotTracker); | ||||||||
| O << " +"; | ||||||||
| if (isa<FPMathOperator>(getUnderlyingInstr())) | ||||||||
| O << getUnderlyingInstr()->getFastMathFlags(); | ||||||||
| printFlags(O); | ||||||||
| O << " reduce." << Instruction::getOpcodeName(RdxDesc.getOpcode()) << " ("; | ||||||||
| getVecOp()->printAsOperand(O, SlotTracker); | ||||||||
| if (isConditional()) { | ||||||||
|
|
@@ -2370,7 +2371,7 @@ void VPReductionEVLRecipe::print(raw_ostream &O, const Twine &Indent, | |||||||
| getChainOp()->printAsOperand(O, SlotTracker); | ||||||||
| O << " +"; | ||||||||
| if (isa<FPMathOperator>(getUnderlyingInstr())) | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not major but if we add back the isa check then we remove the diff for the integer reduction test
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add it back the prevent integer reduction test changes.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can we end up with integer reductions with FMFs set?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I understand an integer RecurrenceDescriptor has all fast math flags set: llvm-project/llvm/lib/Analysis/IVDescriptors.cpp Lines 286 to 288 in 6eb32a2
So currently today an integer VPReductionRecipe will use a builder with all fast math flags set: IRBuilderBase::FastMathFlagGuard FMFGuard(State.Builder);
State.Builder.setFastMathFlags(RdxDesc.getFastMathFlags());
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but we shouldn't further propagate incorrect flags to VPReductionRecipe. We should probably check if it is a FP reduction on construction, and if it isn't set empty (fast-math) flags.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. I think @ElvisWang123 had already done something similar in a previous version of this PR like if (isa<FPMathOperator>(I))
setFastMathFlags(R.getFastMathFlags());in the constructor. Should that be done as a part of this PR or in a follow up?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be done straight away, I added a suggested edit
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed checks, thanks! |
||||||||
| O << getUnderlyingInstr()->getFastMathFlags(); | ||||||||
| printFlags(O); | ||||||||
| O << " vp.reduce." << Instruction::getOpcodeName(RdxDesc.getOpcode()) << " ("; | ||||||||
| getVecOp()->printAsOperand(O, SlotTracker); | ||||||||
| O << ", "; | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,7 +167,7 @@ define float @print_reduction(i64 %n, ptr noalias %y) { | |
| ; CHECK-NEXT: CLONE ir<%arrayidx> = getelementptr inbounds ir<%y>, vp<[[STEPS]]> | ||
| ; CHECK-NEXT: vp<[[VEC_PTR:%.+]]> = vector-pointer ir<%arrayidx> | ||
| ; CHECK-NEXT: WIDEN ir<%lv> = load vp<[[VEC_PTR]]> | ||
| ; CHECK-NEXT: REDUCE ir<%red.next> = ir<%red> + fast reduce.fadd (ir<%lv>) | ||
| ; CHECK-NEXT: REDUCE ir<%red.next> = ir<%red> + reassoc nnan ninf nsz arcp contract afn reduce.fadd (ir<%lv>) | ||
|
||
| ; CHECK-NEXT: EMIT vp<[[CAN_IV_NEXT]]> = add nuw vp<[[CAN_IV]]>, vp<[[VFxUF]]> | ||
| ; CHECK-NEXT: EMIT branch-on-count vp<[[CAN_IV_NEXT]]>, vp<[[VTC]]> | ||
| ; CHECK-NEXT: No successors | ||
|
|
@@ -234,7 +234,7 @@ define void @print_reduction_with_invariant_store(i64 %n, ptr noalias %y, ptr no | |
| ; CHECK-NEXT: CLONE ir<%arrayidx> = getelementptr inbounds ir<%y>, vp<[[IV]]> | ||
| ; CHECK-NEXT: vp<[[VEC_PTR:%.+]]> = vector-pointer ir<%arrayidx> | ||
| ; CHECK-NEXT: WIDEN ir<%lv> = load vp<[[VEC_PTR]]> | ||
| ; CHECK-NEXT: REDUCE ir<%red.next> = ir<%red> + fast reduce.fadd (ir<%lv>) (with final reduction value stored in invariant address sank outside of loop) | ||
| ; CHECK-NEXT: REDUCE ir<%red.next> = ir<%red> + reassoc nnan ninf nsz arcp contract afn reduce.fadd (ir<%lv>) (with final reduction value stored in invariant address sank outside of loop) | ||
| ; CHECK-NEXT: EMIT vp<[[CAN_IV_NEXT]]> = add nuw vp<[[CAN_IV]]>, vp<[[VFxUF]]> | ||
| ; CHECK-NEXT: EMIT branch-on-count vp<[[CAN_IV_NEXT]]>, vp<[[VTC]]> | ||
| ; CHECK-NEXT: No successors | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.