[llvm] [SeparateConstOffsetFromGEP] Decompose constant xor operand if possible (PR #135788)
Juan Manuel Martinez CaamaƱo via llvm-commits
llvm-commits at lists.llvm.org
Wed May 14 00:59:12 PDT 2025
================
@@ -486,6 +490,39 @@ class SeparateConstOffsetFromGEP {
DenseMap<ExprKey, SmallVector<Instruction *, 2>> DominatingSubs;
};
+/// A helper class that aims to convert xor operations into or operations when
+/// their operands are disjoint and the result is used in a GEP's index. This
+/// can then enable further GEP optimizations by effectively turning BaseVal |
+/// Const into BaseVal + Const when they are disjoint, which
+/// SeparateConstOffsetFromGEP can then process. This is a common pattern that
+/// sets up a grid of memory accesses across a wave where each thread acesses
+/// data at various offsets.
+class XorToOrDisjointTransformer {
+public:
+ XorToOrDisjointTransformer(Function &F, DominatorTree &DT,
+ const DataLayout &DL)
+ : F(F), DT(DT), DL(DL) {}
+
+ bool run();
+
+private:
+ Function &F;
+ DominatorTree &DT;
+ const DataLayout &DL;
+ /// Maps a common operand to all Xor instructions
+ using XorOpList = SmallVector<std::pair<BinaryOperator *, APInt>, 8>;
+ using XorBaseValMap = DenseMap<Value *, XorOpList>;
+ XorBaseValMap XorGroups;
+
+ /// Checks if the given value has at least one GetElementPtr user
+ bool hasGEPUser(const Value *V) const;
----------------
jmmartinez wrote:
Function doesn't access the state of the object.
```suggestion
static bool hasGEPUser(const Value *V);
```
https://github.com/llvm/llvm-project/pull/135788
More information about the llvm-commits
mailing list