[llvm] [SelectionDAG] Introduce ISD::PTRADD (PR #140017)

Fabian Ritter via llvm-commits llvm-commits at lists.llvm.org
Fri May 16 01:09:15 PDT 2025


================
@@ -469,9 +470,13 @@ class TargetMachine {
   }
 
   /// True if target has some particular form of dealing with pointer arithmetic
-  /// semantics. False if pointer arithmetic should not be preserved for passes
-  /// such as instruction selection, and can fallback to regular arithmetic.
-  virtual bool shouldPreservePtrArith(const Function &F) const { return false; }
+  /// semantics for pointers with the given value type. False if pointer
+  /// arithmetic should not be preserved for passes such as instruction
+  /// selection, and can fallback to regular arithmetic.
+  virtual bool shouldPreservePtrArith(const Function &F,
+                                      const EVT &PtrVT) const {
----------------
ritter-x2a wrote:

I didn't pass it by value to avoid including the `ValueTypes.h` header in this header (and the potential compile-time cost), but I can change that.

We don't have the IR type in `SelectionDAG::getMemBasePlusOffset`, where this function is called (unless I'm missing a way to retrieve it from an SDValue). That function is not only used to lower GEPs in the builder, but also for places in legalization (e.g., for loads and stores of too-wide vector types), where there isn't necessarily a matching IR type.

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


More information about the llvm-commits mailing list