[llvm] [VPlan] Introduce VPlanConstantFolder (PR #125365)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon May 5 13:02:37 PDT 2025
================
@@ -937,10 +938,84 @@ static void recursivelyDeleteDeadRecipes(VPValue *V) {
}
}
+class VPConstantFolder {
+ TargetFolder Folder;
+ VPTypeAnalysis TypeInfo;
+
+public:
+ VPConstantFolder(const DataLayout &DL, const VPTypeAnalysis &TypeInfo)
+ : Folder(DL), TypeInfo(TypeInfo) {}
+
+ Value *tryToConstantFold(VPRecipeBase &R, unsigned Opcode,
+ ArrayRef<VPValue *> Operands) {
+ SmallVector<Value *, 4> Ops;
+ for (VPValue *Op : Operands) {
+ if (!Op->isLiveIn() || !Op->getLiveInIRValue())
+ return nullptr;
+ Ops.emplace_back(Op->getLiveInIRValue());
+ }
+ switch (Opcode) {
+ case Instruction::BinaryOps::Add:
+ case Instruction::BinaryOps::Sub:
+ case Instruction::BinaryOps::Mul:
+ case Instruction::BinaryOps::AShr:
+ case Instruction::BinaryOps::LShr:
+ case Instruction::BinaryOps::And:
+ case Instruction::BinaryOps::Or:
+ case Instruction::BinaryOps::Xor:
----------------
fhahn wrote:
Could catch all of those (and possibly more) via `Instruction::isBinaryOp`, same for unary ops.
https://github.com/llvm/llvm-project/pull/125365
More information about the llvm-commits
mailing list