[llvm] 4a578be - PPC: Avoid constructing TargetTransformInfo in isHardwareLoopProfitable (#209972)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 16 10:07:01 PDT 2026
Author: Matt Arsenault
Date: 2026-07-16T19:06:57+02:00
New Revision: 4a578be311736c684214e87aa07800cd76dd2471
URL: https://github.com/llvm/llvm-project/commit/4a578be311736c684214e87aa07800cd76dd2471
DIFF: https://github.com/llvm/llvm-project/commit/4a578be311736c684214e87aa07800cd76dd2471.diff
LOG: PPC: Avoid constructing TargetTransformInfo in isHardwareLoopProfitable (#209972)
PPCTTIImpl::isHardwareLoopProfitable constructed a throwaway
TargetTransformInfo only to call CodeMetrics::analyzeBasicBlock. TTI
may contain pipeline configuration state, and should only be queried
from the PassManager. It was also particularly ugly to construct one
here given that we're inside a TTIImpl.
Most of what analyzeBasicBlock computes was not used here. Directly
sum the instruction code size costs, which was the only used component
of the analysis.
Co-authored-by: Claude (Claude Opus 4.8) <noreply at anthropic.com>
Added:
Modified:
llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
index a64471b627d7d..b3a54fd4c1ef4 100644
--- a/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
+++ b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
@@ -352,20 +352,22 @@ bool PPCTTIImpl::isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
TargetSchedModel SchedModel;
SchedModel.init(ST);
- // FIXME: Sure there is no other way to get TTI? This should be cheap though.
- TargetTransformInfo TTI =
- TM.getTargetTransformInfo(*L->getHeader()->getParent());
-
// Do not convert small short loops to CTR loop.
unsigned ConstTripCount = SE.getSmallConstantTripCount(L);
if (ConstTripCount && ConstTripCount < SmallCTRLoopThreshold) {
SmallPtrSet<const Value *, 32> EphValues;
CodeMetrics::collectEphemeralValues(L, &AC, EphValues);
- CodeMetrics Metrics;
- for (BasicBlock *BB : L->blocks())
- Metrics.analyzeBasicBlock(BB, TTI, EphValues);
+ InstructionCost NumInsts;
+ for (BasicBlock *BB : L->blocks()) {
+ for (Instruction &I : *BB) {
+ if (EphValues.count(&I))
+ continue;
+ SmallVector<const Value *, 4> Operands(I.operand_values());
+ NumInsts += getInstructionCost(&I, Operands, TTI::TCK_CodeSize);
+ }
+ }
// 6 is an approximate latency for the mtctr instruction.
- if (Metrics.NumInsts <= (6 * SchedModel.getIssueWidth()))
+ if (NumInsts <= (6 * SchedModel.getIssueWidth()))
return false;
}
More information about the llvm-commits
mailing list