[PATCH] D41026: [InstComineLoadStoreAlloca] Optimize stores to GEP off null base

Sanjoy Das via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 8 11:25:48 PST 2017


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

lgtm



================
Comment at: lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp:935
+static bool canSimplifyNullStoreOrGEP(StoreInst &SI) {
+  auto *Ptr = SI.getPointerOperand();
+  if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Ptr)) {
----------------
Minor bikeshed -- how about checking `SI.getPointerAddressSpace() == 0` with an early exit?


================
Comment at: lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp:937
+  if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Ptr)) {
+    const Value *GEPI0 = GEPI->getOperand(0);
+    if (isa<ConstantPointerNull>(GEPI0) && GEPI->getPointerAddressSpace() == 0)
----------------
How about:

```
if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Ptr))
  Ptr = GEPI->getOperand(0);
// Logic for Ptr here
```
?


https://reviews.llvm.org/D41026





More information about the llvm-commits mailing list