[PATCH] D105088: [InstCombine] Fold IntToPtr/PtrToInt to bitcast

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 16 13:32:00 PDT 2021


nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.

LGTM



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:4571
 Instruction *InstCombinerImpl::foldICmpWithCastOp(ICmpInst &ICmp) {
+  // icmp (inttoptr (ptrtoint p1)), p2 --> icmp p1, p2.
+  Value *SimplifiedOp0 = simplifyIntToPtrRoundTripCast(ICmp.getOperand(0));
----------------
Maybe add a brief comment here that explains why it is legal? Just "because icmp doesn't care about provenance" should do.


================
Comment at: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:352
+Value *InstCombinerImpl::simplifyIntToPtrRoundTripCast(Value *Val) {
+  auto *Cast = dyn_cast<CastInst>(Val);
+  if (!Cast)
----------------
You could directly cast to IntToPtrInst here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105088



More information about the llvm-commits mailing list