[llvm] VPlan: use worklist in simplifyRecipes (PR #93998)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 21 03:55:04 PDT 2024
================
@@ -1046,23 +1048,73 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
assert(TypeInfo.inferScalarType(VPV) == TypeInfo2.inferScalarType(VPV));
}
#endif
+ if (VPC)
+ return {VPC};
+ return {};
+ }
+
+ VPValue *X, *X1, *Y, *Z;
+
+ // (X || !X) -> true.
+ if (match(&R, m_c_BinaryOr(m_VPValue(X), m_Not(m_VPValue(X1)))) && X == X1) {
+ auto *VPV = new VPValue(ConstantInt::getTrue(Ctx));
+ R.getVPSingleValue()->replaceAllUsesWith(VPV);
+ return {};
+ }
+
+ // (X || true) -> true.
+ if (match(&R, m_c_BinaryOr(m_VPValue(X), m_True()))) {
+ auto *VPV = new VPValue(ConstantInt::getTrue(Ctx));
+ R.getVPSingleValue()->replaceAllUsesWith(VPV);
+ return {};
}
- // Simplify (X && Y) || (X && !Y) -> X.
- // TODO: Split up into simpler, modular combines: (X && Y) || (X && Z) into X
- // && (Y || Z) and (X || !X) into true. This requires queuing newly created
- // recipes to be visited during simplification.
- VPValue *X, *Y, *X1, *Y1;
- if (match(&R,
- m_c_BinaryOr(m_LogicalAnd(m_VPValue(X), m_VPValue(Y)),
- m_LogicalAnd(m_VPValue(X1), m_Not(m_VPValue(Y1))))) &&
- X == X1 && Y == Y1) {
+ // (X || false) -> X.
+ if (match(&R, m_c_BinaryOr(m_VPValue(X), m_False()))) {
R.getVPSingleValue()->replaceAllUsesWith(X);
- return;
+ return {};
+ }
+
+ // (X && !X) -> false.
+ if (match(&R, m_LogicalAnd(m_VPValue(X), m_Not(m_VPValue(X1)))) && X == X1) {
+ auto *VPV = new VPValue(ConstantInt::getFalse(Ctx));
+ R.getVPSingleValue()->replaceAllUsesWith(VPV);
+ return {};
+ }
+
+ // (X && true) -> X.
+ if (match(&R, m_LogicalAnd(m_VPValue(X), m_True()))) {
+ R.getVPSingleValue()->replaceAllUsesWith(X);
+ return {};
+ }
+
+ // (X && false) -> false.
+ if (match(&R, m_LogicalAnd(m_VPValue(X), m_False()))) {
+ auto *VPV = new VPValue(ConstantInt::getFalse(Ctx));
+ R.getVPSingleValue()->replaceAllUsesWith(VPV);
+ return {};
+ }
+
+ // (X * 1) -> X.
+ if (match(&R, m_c_Mul(m_VPValue(X), m_SpecificInt(1)))) {
+ R.getVPSingleValue()->replaceAllUsesWith(X);
+ return {};
}
- if (match(&R, m_c_Mul(m_VPValue(A), m_SpecificInt(1))))
- return R.getVPSingleValue()->replaceAllUsesWith(A);
+ // (X && Y) || (X && Z) -> X && (Y || Z).
+ if (match(&R, m_BinaryOr(m_LogicalAnd(m_VPValue(X), m_VPValue(Y)),
+ m_LogicalAnd(m_VPValue(X1), m_VPValue(Z)))) &&
+ X == X1) {
+ auto *YorZ = new VPInstruction(Instruction::Or, {Y, Z}, R.getDebugLoc());
----------------
fhahn wrote:
Better to use VPBuilder to construct & Insert the new instructions?
https://github.com/llvm/llvm-project/pull/93998
More information about the llvm-commits
mailing list