[llvm] [SeparateConstOffsetFromGEP] Accumulate offsets across expression trees (PR #230637)

Krzysztof Drewniak via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 9 13:06:00 PDT 2026


================
@@ -309,24 +313,20 @@ class ConstantOffsetExtractor {
   ///   Analysis: DisjointBits = 3 & KnownZeros(%ptr) = 0b11 & 0b01 = 0b01
   ///   Result:   `(xor %ptr, 2) + 1` where 1 can be folded into address mode
   ///
-  /// \param XorInst The XOR binary operator to analyze
-  /// \return Returns the disjoint bits (the extractable offset), or
-  /// std::nullopt if none exist. On success, stores NonDisjointBits in
-  /// NonDisjointXorConstantBits.
-  std::optional<APInt> extractDisjointBitsFromXor(BinaryOperator *XorInst);
-
-  /// The non-disjoint bits remaining after xor decomposition in
-  /// `extractDisjointBitsFromXor`, which are later used while replacing the
-  /// original xor constant operand.
-  ConstantInt *NonDisjointXorConstantBits = nullptr;
-
-  /// The path from the constant offset to the old GEP index. e.g., if the GEP
-  /// index is "a * b + (c + 5)". After running function find, UserChain[0] will
-  /// be the constant 5, UserChain[1] will be the subexpression "c + 5", and
-  /// UserChain[2] will be the entire expression "a * b + (c + 5)".
-  ///
-  /// This path helps to rebuild the new GEP index.
-  SmallVector<User *, 8> UserChain;
+  /// \param Node The XOR node to analyze.
+  /// \return The disjoint bits (the extractable offset), or std::nullopt if
+  /// none exist. On success, records the remaining constant as a child node.
+  std::optional<APInt> extractDisjointBitsFromXor(RewriteNode &Node);
+
+  /// A postorder rewrite plan. Child indices refer to earlier entries; absent
+  /// children leave the original operands unchanged. Constant leaves hold
+  /// replacement values rather than the constants being extracted.
+  SmallVector<RewriteNode, 8> UserTree;
+
+  static constexpr unsigned MaxVisitedNodes = 64;
----------------
krzysz00 wrote:

Hopefully this doesn't regress anything

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


More information about the llvm-commits mailing list