[llvm-branch-commits] [llvm] release/22.x: [SystemZ] Limit depth of findCCUse() (#185922) (PR #186052)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Mar 12 01:12:04 PDT 2026
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/186052
Backport 11e0d6ae4b00114d642f03168f57a007464bf5f6
Requested by: @nikic
>From 8e18855761a69bba7ba2ead63f54c8e464240ce9 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 12 Mar 2026 09:00:38 +0100
Subject: [PATCH] [SystemZ] Limit depth of findCCUse() (#185922)
The recursion here has potentially exponential complexity. Avoid this by
limiting the depth of recursion.
An alternative would be to memoize the results. I went with the simpler
depth limit on the assumption that we don't particularly care about very
deep value chains here.
Fixes https://github.com/llvm/llvm-project/issues/185905.
(cherry picked from commit 11e0d6ae4b00114d642f03168f57a007464bf5f6)
---
llvm/lib/Target/SystemZ/SystemZISelLowering.cpp | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
index 21beef238f187..8f21e00983601 100644
--- a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
@@ -8705,7 +8705,12 @@ SDValue SystemZTargetLowering::combineSETCC(
return SDValue();
}
-static std::pair<SDValue, int> findCCUse(const SDValue &Val) {
+static std::pair<SDValue, int> findCCUse(const SDValue &Val,
+ unsigned Depth = 0) {
+ // Limit depth of potentially exponential walk.
+ if (Depth > 5)
+ return std::make_pair(SDValue(), SystemZ::CCMASK_NONE);
+
switch (Val.getOpcode()) {
default:
return std::make_pair(SDValue(), SystemZ::CCMASK_NONE);
@@ -8718,7 +8723,7 @@ static std::pair<SDValue, int> findCCUse(const SDValue &Val) {
SDValue Op4CCReg = Val.getOperand(4);
if (Op4CCReg.getOpcode() == SystemZISD::ICMP ||
Op4CCReg.getOpcode() == SystemZISD::TM) {
- auto [OpCC, OpCCValid] = findCCUse(Op4CCReg.getOperand(0));
+ auto [OpCC, OpCCValid] = findCCUse(Op4CCReg.getOperand(0), Depth + 1);
if (OpCC != SDValue())
return std::make_pair(OpCC, OpCCValid);
}
@@ -8735,10 +8740,10 @@ static std::pair<SDValue, int> findCCUse(const SDValue &Val) {
case ISD::SHL:
case ISD::SRA:
case ISD::SRL:
- auto [Op0CC, Op0CCValid] = findCCUse(Val.getOperand(0));
+ auto [Op0CC, Op0CCValid] = findCCUse(Val.getOperand(0), Depth + 1);
if (Op0CC != SDValue())
return std::make_pair(Op0CC, Op0CCValid);
- return findCCUse(Val.getOperand(1));
+ return findCCUse(Val.getOperand(1), Depth + 1);
}
}
More information about the llvm-branch-commits
mailing list