[llvm] [SCEV] Handle all PtrtoIntExpr construction in CastSinkingRewriter (NFC) (PR #174435)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 6 13:04:51 PST 2026
================
@@ -1007,26 +1007,73 @@ SCEVAddRecExpr::evaluateAtIteration(ArrayRef<const SCEV *> Operands,
// SCEV Expression folder implementations
//===----------------------------------------------------------------------===//
-const SCEV *ScalarEvolution::getLosslessPtrToIntExpr(const SCEV *Op,
- unsigned Depth) {
- assert(Depth <= 1 &&
- "getLosslessPtrToIntExpr() should self-recurse at most once.");
+/// The SCEVCastSinkingRewriter takes a scalar evolution expression,
+/// which computes a pointer-typed value, and rewrites the whole expression
+/// tree so that *all* the computations are done on integers, and the only
+/// pointer-typed operands in the expression are SCEVUnknown.
+/// The CreatePtrCast callback is invoked to create the actual conversion
+/// (ptrtoint or ptrtoaddr) at the SCEVUnknown leaves.
+class SCEVCastSinkingRewriter
+ : public SCEVRewriteVisitor<SCEVCastSinkingRewriter> {
+ using Base = SCEVRewriteVisitor<SCEVCastSinkingRewriter>;
+ using ConversionFn = std::function<const SCEV *(const SCEVUnknown *)>;
----------------
nikic wrote:
```suggestion
using ConversionFn = function_ref<const SCEV *(const SCEVUnknown *)>;
```
https://github.com/llvm/llvm-project/pull/174435
More information about the llvm-commits
mailing list