[PATCH] D69470: [ExpandReductions] Don't push all intrinsics to the worklist. Just push reductions.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 26 18:14:19 PDT 2019
craig.topper created this revision.
craig.topper added reviewers: RKSimon, spatel, aemerson.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
We were previously pushing all intrinsics used in a function to the
worklist. This is wasteful for memory in a function with a lot of
intrinsics.
We also ask TTI if we should expand every intrinsic, but we only
have expansion support for the reduction intrinsics. This just
wastes time for the non-reduction intrinsics.
This patch only pushes reduction intrinsics into the worklist and
skips other intrinsics.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D69470
Files:
llvm/lib/CodeGen/ExpandReductions.cpp
Index: llvm/lib/CodeGen/ExpandReductions.cpp
===================================================================
--- llvm/lib/CodeGen/ExpandReductions.cpp
+++ llvm/lib/CodeGen/ExpandReductions.cpp
@@ -78,9 +78,28 @@
bool expandReductions(Function &F, const TargetTransformInfo *TTI) {
bool Changed = false;
SmallVector<IntrinsicInst *, 4> Worklist;
- for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
- if (auto II = dyn_cast<IntrinsicInst>(&*I))
- Worklist.push_back(II);
+ for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
+ if (auto II = dyn_cast<IntrinsicInst>(&*I)) {
+ switch (II->getIntrinsicID()) {
+ default: break;
+ case Intrinsic::experimental_vector_reduce_v2_fadd:
+ case Intrinsic::experimental_vector_reduce_v2_fmul:
+ case Intrinsic::experimental_vector_reduce_add:
+ case Intrinsic::experimental_vector_reduce_mul:
+ case Intrinsic::experimental_vector_reduce_and:
+ case Intrinsic::experimental_vector_reduce_or:
+ case Intrinsic::experimental_vector_reduce_xor:
+ case Intrinsic::experimental_vector_reduce_smax:
+ case Intrinsic::experimental_vector_reduce_smin:
+ case Intrinsic::experimental_vector_reduce_umax:
+ case Intrinsic::experimental_vector_reduce_umin:
+ case Intrinsic::experimental_vector_reduce_fmax:
+ case Intrinsic::experimental_vector_reduce_fmin:
+ Worklist.push_back(II);
+ break;
+ }
+ }
+ }
for (auto *II : Worklist) {
if (!TTI->shouldExpandReduction(II))
@@ -96,6 +115,7 @@
IRBuilder<>::FastMathFlagGuard FMFGuard(Builder);
Builder.setFastMathFlags(FMF);
switch (ID) {
+ default: llvm_unreachable("Unexpected intrinsic!");
case Intrinsic::experimental_vector_reduce_v2_fadd:
case Intrinsic::experimental_vector_reduce_v2_fmul: {
// FMFs must be attached to the call, otherwise it's an ordered reduction
@@ -109,7 +129,8 @@
Rdx = Builder.CreateBinOp((Instruction::BinaryOps)getOpcode(ID),
Acc, Rdx, "bin.rdx");
}
- } break;
+ break;
+ }
case Intrinsic::experimental_vector_reduce_add:
case Intrinsic::experimental_vector_reduce_mul:
case Intrinsic::experimental_vector_reduce_and:
@@ -123,9 +144,8 @@
case Intrinsic::experimental_vector_reduce_fmin: {
Value *Vec = II->getArgOperand(0);
Rdx = getShuffleReduction(Builder, Vec, getOpcode(ID), MRK);
- } break;
- default:
- continue;
+ break;
+ }
}
II->replaceAllUsesWith(Rdx);
II->eraseFromParent();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69470.226558.patch
Type: text/x-patch
Size: 2624 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191027/2026c039/attachment.bin>
More information about the llvm-commits
mailing list