[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 21 04:10:57 PDT 2025


================
@@ -1335,9 +1335,11 @@ bool XorToOrDisjointTransformer::run() {
         Value *Op0 = XorOp->getOperand(0);
         ConstantInt *C1 = nullptr;
         // Match: xor Op0, Constant
-        if (match(XorOp->getOperand(1), m_ConstantInt(C1))) {
+        if (isa<Instruction>(Op0) &&
+            match(XorOp->getOperand(1), m_ConstantInt(C1))) {
----------------
jmmartinez wrote:

We could either rely on match or use `dyn_cast`, but currently this is using a mix of both:
* `isa` + `cast` (which could be a `dyn_cast`) for checking if Op0 is an Instruction / if `I` is a xor
* `match` for checking if the second operand is a constant

I think this for loop could be written as:

```cpp
  for (Instruction &I : instructions(F)) {
    BinaryOperator *XorOp;
    Instruction *Op0;
    ConstantInt *C1;
    if(match(&I, m_CombineAnd(m_Xor(m_Instruction(Op0), m_ConstantInt(C1)), m_BinOp(XorOp))) && hasGEPUser(XorOp)) {
       XorGroups.try_emplace(Op0, {{XorOp, C1->getValue()}});
    }
  }
```

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


More information about the llvm-commits mailing list