[llvm] [InstCombine] Offset both sides of an equality icmp (PR #134086)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 22 21:42:34 PDT 2025


================
@@ -5808,6 +5808,134 @@ static Instruction *foldICmpPow2Test(ICmpInst &I,
   return nullptr;
 }
 
+/// Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
+using OffsetOp = std::pair<Instruction::BinaryOps, Value *>;
+static void collectOffsetOp(Value *V, SmallVectorImpl<OffsetOp> &Offsets,
+                            bool AllowRecursion) {
+  Instruction *Inst = dyn_cast<Instruction>(V);
+  if (!Inst)
+    return;
+  Constant *C;
+
+  switch (Inst->getOpcode()) {
+  case Instruction::Add:
+    if (match(Inst->getOperand(1), m_ImmConstant(C)) &&
----------------
dianqk wrote:

```suggestion
  switch (Inst->getOpcode()) {
  case Instruction::Add:
    Constant *C;
    if (match(Inst->getOperand(1), m_ImmConstant(C)) &&
```

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


More information about the llvm-commits mailing list