[llvm] fec64de - [VPlan] Use VPValue def for VPWidenCall.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 9 05:41:10 PST 2020
Author: Florian Hahn
Date: 2020-11-09T13:29:41Z
New Revision: fec64de261ff7ca2f56707d3d5e12e917b929c67
URL: https://github.com/llvm/llvm-project/commit/fec64de261ff7ca2f56707d3d5e12e917b929c67
DIFF: https://github.com/llvm/llvm-project/commit/fec64de261ff7ca2f56707d3d5e12e917b929c67.diff
LOG: [VPlan] Use VPValue def for VPWidenCall.
This patch turns VPWidenCall into a VPValue and uses it
during VPlan construction and codegeneration instead of the plain IR
reference where possible.
Reviewed By: dmgreen
Differential Revision: https://reviews.llvm.org/D84681
Added:
llvm/test/Transforms/LoopVectorize/vplan-printing.ll
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/lib/Transforms/Vectorize/VPlanValue.h
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 27edfd61b3f2..e47cde990eca 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -465,7 +465,7 @@ class InnerLoopVectorizer {
VPTransformState &State);
/// Widen a single call instruction within the innermost loop.
- void widenCallInstruction(CallInst &I, VPUser &ArgOperands,
+ void widenCallInstruction(CallInst &I, VPValue *Def, VPUser &ArgOperands,
VPTransformState &State);
/// Widen a single select instruction within the innermost loop.
@@ -4616,7 +4616,8 @@ void InnerLoopVectorizer::widenInstruction(Instruction &I, VPUser &User,
} // end of switch.
}
-void InnerLoopVectorizer::widenCallInstruction(CallInst &I, VPUser &ArgOperands,
+void InnerLoopVectorizer::widenCallInstruction(CallInst &I, VPValue *Def,
+ VPUser &ArgOperands,
VPTransformState &State) {
assert(!isa<DbgInfoIntrinsic>(I) &&
"DbgInfoIntrinsic should have been dropped during VPlan construction");
@@ -4680,7 +4681,7 @@ void InnerLoopVectorizer::widenCallInstruction(CallInst &I, VPUser &ArgOperands,
if (isa<FPMathOperator>(V))
V->copyFastMathFlags(CI);
- VectorLoopValueMap.setVectorValue(&I, Part, V);
+ State.set(Def, &I, V, Part);
addMetadata(V, &I);
}
}
@@ -7993,7 +7994,8 @@ void VPInterleaveRecipe::print(raw_ostream &O, const Twine &Indent,
}
void VPWidenCallRecipe::execute(VPTransformState &State) {
- State.ILV->widenCallInstruction(Ingredient, *this, State);
+ State.ILV->widenCallInstruction(*cast<CallInst>(getUnderlyingInstr()), this,
+ *this, State);
}
void VPWidenSelectRecipe::execute(VPTransformState &State) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 4a3ad0e1eaae..78e58c24f994 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -106,6 +106,8 @@ VPValue *VPRecipeBase::toVPValue() {
return V;
if (auto *V = dyn_cast<VPWidenMemoryInstructionRecipe>(this))
return V;
+ if (auto *V = dyn_cast<VPWidenCallRecipe>(this))
+ return V;
return nullptr;
}
@@ -114,6 +116,8 @@ const VPValue *VPRecipeBase::toVPValue() const {
return V;
if (auto *V = dyn_cast<VPWidenMemoryInstructionRecipe>(this))
return V;
+ if (auto *V = dyn_cast<VPWidenCallRecipe>(this))
+ return V;
return nullptr;
}
@@ -822,7 +826,19 @@ void VPlanPrinter::printAsIngredient(raw_ostream &O, const Value *V) {
void VPWidenCallRecipe::print(raw_ostream &O, const Twine &Indent,
VPSlotTracker &SlotTracker) const {
- O << "\"WIDEN-CALL " << VPlanIngredient(&Ingredient);
+ O << "\"WIDEN-CALL ";
+
+ auto *CI = cast<CallInst>(getUnderlyingInstr());
+ if (CI->getType()->isVoidTy())
+ O << "void ";
+ else {
+ printAsOperand(O, SlotTracker);
+ O << " = ";
+ }
+
+ O << "call @" << CI->getCalledFunction()->getName() << "(";
+ printOperands(O, SlotTracker);
+ O << ")";
}
void VPWidenSelectRecipe::print(raw_ostream &O, const Twine &Indent,
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 56b19b517a23..b037e376ed52 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -853,14 +853,13 @@ class VPWidenRecipe : public VPRecipeBase, public VPUser {
};
/// A recipe for widening Call instructions.
-class VPWidenCallRecipe : public VPRecipeBase, public VPUser {
- /// Hold the call to be widened.
- CallInst &Ingredient;
+class VPWidenCallRecipe : public VPRecipeBase, public VPValue, public VPUser {
public:
template <typename IterT>
VPWidenCallRecipe(CallInst &I, iterator_range<IterT> CallArguments)
- : VPRecipeBase(VPWidenCallSC), VPUser(CallArguments), Ingredient(I) {}
+ : VPRecipeBase(VPRecipeBase::VPWidenCallSC),
+ VPValue(VPValue::VPVWidenCallSC, &I), VPUser(CallArguments) {}
~VPWidenCallRecipe() override = default;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h
index f18b6f94c986..503abec30c66 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanValue.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h
@@ -78,7 +78,7 @@ class VPValue {
/// are actually instantiated. Values of this enumeration are kept in the
/// SubclassID field of the VPValue objects. They are used for concrete
/// type identification.
- enum { VPValueSC, VPInstructionSC, VPMemoryInstructionSC };
+ enum { VPValueSC, VPInstructionSC, VPMemoryInstructionSC, VPVWidenCallSC };
VPValue(Value *UV = nullptr) : VPValue(VPValueSC, UV) {}
VPValue(const VPValue &) = delete;
diff --git a/llvm/test/Transforms/LoopVectorize/vplan-printing.ll b/llvm/test/Transforms/LoopVectorize/vplan-printing.ll
new file mode 100644
index 000000000000..ce819d20e813
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/vplan-printing.ll
@@ -0,0 +1,39 @@
+; REQUIRES: asserts
+
+; RUN: opt -loop-vectorize -debug-only=loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -disable-output %s 2>&1 | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+
+; Tests for printing VPlans.
+
+define void @print_call_and_memory(i64 %n, float* noalias %y, float* noalias %x) nounwind uwtable {
+; CHECK: N0 [label =
+; CHECK-NEXT: "for.body:\n" +
+; CHECK-NEXT: "WIDEN-INDUCTION %iv = phi %iv.next, 0\l" +
+; CHECK-NEXT: "CLONE %arrayidx = getelementptr %y, %iv\l" +
+; CHECK-NEXT: "WIDEN load ir<%arrayidx>\l" +
+; CHECK-NEXT: "WIDEN-CALL ir<%call> = call @llvm.sqrt.f32(ir<%lv>)\l" +
+; CHECK-NEXT: "CLONE %arrayidx2 = getelementptr %x, %iv\l" +
+; CHECK-NEXT: "WIDEN store ir<%arrayidx2>, ir<%call>\l"
+; CHECK-NEXT: ]
+
+entry:
+ %cmp6 = icmp sgt i64 %n, 0
+ br i1 %cmp6, label %for.body, label %for.end
+
+for.body: ; preds = %entry, %for.body
+ %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
+ %arrayidx = getelementptr inbounds float, float* %y, i64 %iv
+ %lv = load float, float* %arrayidx, align 4
+ %call = tail call float @llvm.sqrt.f32(float %lv) nounwind readnone
+ %arrayidx2 = getelementptr inbounds float, float* %x, i64 %iv
+ store float %call, float* %arrayidx2, align 4
+ %iv.next = add i64 %iv, 1
+ %exitcond = icmp eq i64 %iv.next, %n
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body, %entry
+ ret void
+}
+
+declare float @llvm.sqrt.f32(float) nounwind readnone
More information about the llvm-commits
mailing list