[PATCH] D142542: [InstSimplify] Simplify icmp between Shl instructions of the same value

Matt Devereau via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 31 06:00:58 PST 2023


MattDevereau marked 3 inline comments as done.
MattDevereau added inline comments.


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:3674
+    return nullptr;
+  };
+}
----------------
nikic wrote:
> There is an ICmpInst::compare() helper that takes a predicate and APInts -- this code can probably be simplified based on that?
`ICmpInst::compare()` works perfectly, thank you


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:3991
+  if (Value *V = simplifyICmpLShiftedValues(Pred, LHS, RHS, Q))
+    return V;
+
----------------
nikic wrote:
> Should probably be called from simplifyICmpWithBinOp. Also, it looks like a very similar fold already exists there: https://github.com/llvm/llvm-project/blob/bde5d31e96f556fed30bf9120cc6ff05a2116b64/llvm/lib/Analysis/InstructionSimplify.cpp#L3426-L3436 This seems to be the same, just on different operands of the shift. Possibly that could serve as inspiration on how to implement this more compactly.
I've moved this to be inside `simplifyICmpWithBinOp` and close to where you suggested. However this required checking the 0th operands of the binops for equality instead of comparing the 1st operands of the binops like where you suggested did.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142542/new/

https://reviews.llvm.org/D142542



More information about the llvm-commits mailing list