[PATCH] D105002: [InferAddressSpaces] NFC: For noop IntToPtr/PtrToInt pair cast to operator instead of PtrToInt

Michael Liao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 28 06:43:21 PDT 2021


hliao added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp:473
       if (isNoopPtrIntCastPair(cast<Operator>(I2P), *DL, TTI))
-        PushPtrOperand(
-            cast<PtrToIntInst>(I2P->getOperand(0))->getPointerOperand());
+        if (PtrToIntInst *P2I = dyn_cast<PtrToIntInst>(I2P->getOperand(0)))
+          PushPtrOperand(P2I->getPointerOperand());
----------------
arsenm wrote:
> rksharma wrote:
> > rksharma wrote:
> > > arsenm wrote:
> > > > Can't you access the operator operand anyway and still handle constant expressions?
> > > Are you saying something like,  
> > > ```
> > > PushPtrOperand(cast<Operator>(I2P->getOperand(0))->getOperand(0));
> > > ```
> > Yes, this will work because it does check for constant expressions inside PushPtrOperand
> Yes
> Yes, this will work because it does check for constant expressions inside PushPtrOperand

That original cast is unnecessary and should be removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105002



More information about the llvm-commits mailing list