[llvm] [LoopFusion] Simplify the logic of checking trip count equality (NFCI). (PR #201446)
Ehsan Amiri via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 5 09:13:44 PDT 2026
================
@@ -755,34 +742,20 @@ struct LoopFuser {
FC0.verify();
FC1.verify();
- // Check if the candidates have identical tripcounts (first value of
- // pair), and if not check the difference in the tripcounts between
- // the loops (second value of pair). The difference is not equal to
- // std::nullopt iff the loops iterate a constant number of times, and
- // have a single exit.
- std::pair<bool, std::optional<unsigned>> IdenticalTripCountRes =
- haveIdenticalTripCounts(FC0, FC1);
- bool SameTripCount = IdenticalTripCountRes.first;
- std::optional<unsigned> TCDifference = IdenticalTripCountRes.second;
-
+ std::optional<int64_t> TCDifference = calculateTripCountDiff(FC0, FC1);
// Here we are checking that FC0 (the first loop) can be peeled, and
- // both loops have different tripcounts.
- if (FC0.AbleToPeel && !SameTripCount && TCDifference) {
- if (*TCDifference > FusionPeelMaxCount) {
- LLVM_DEBUG(dbgs()
- << "Difference in loop trip counts: " << *TCDifference
- << " is greater than maximum peel count specificed: "
- << FusionPeelMaxCount << "\n");
- } else {
- // Dependent on peeling being performed on the first loop, and
- // assuming all other conditions for fusion return true.
- SameTripCount = true;
- }
- }
-
- if (!SameTripCount) {
+ // the first loop has a larger trip count. In this case it is possible
+ // that the first loop is peeled to expose the fusion opportunity.
+ // Peeling the second loop is not currently supported.
+ bool WillPeel = false;
+ if (FC0.AbleToPeel && TCDifference && *TCDifference > 0 &&
----------------
amehsan wrote:
actually, I think this could be a good patch for one of our new open source contributors. I am going to merge this and we will change the code so we can distinguish more than one case in debug messages. (maybe just two or maybe all the four cases above).
https://github.com/llvm/llvm-project/pull/201446
More information about the llvm-commits
mailing list