[llvm] [IVDesc] Use SCEVPatternMatch to improve code (NFC) (PR #168397)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 18 01:54:57 PST 2025


================
@@ -1395,10 +1398,11 @@ InductionDescriptor::InductionDescriptor(Value *Start, InductionKind K,
     llvm::append_range(RedundantCasts, *Casts);
 }
 
-ConstantInt *InductionDescriptor::getConstIntStepValue() const {
-  if (isa<SCEVConstant>(Step))
-    return dyn_cast<ConstantInt>(cast<SCEVConstant>(Step)->getValue());
-  return nullptr;
+const APInt *InductionDescriptor::getStepValue() const {
+  const APInt *StepC;
+  if (!match(Step, m_scev_APInt(StepC)))
+    return nullptr;
+  return StepC;
----------------
fhahn wrote:

Might be worth to keep the original code here, as pattern matching is slightly more verbose?

Or something like that 
```suggestion
  if (auto *C = dyn_cast<SCEVConstant>(Step))
    return dyn_cast<ConstantInt>(C->getValue());
  return nullptr;
```

https://github.com/llvm/llvm-project/pull/168397


More information about the llvm-commits mailing list