[PATCH] D41026: [InstComineLoadStoreAlloca] Optimize stores to GEP off null base
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 12 06:13:23 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL320480: [InstComineLoadStoreAlloca] Optimize stores to GEP off null base (authored by annat, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D41026?vs=126183&id=126539#toc
Repository:
rL LLVM
https://reviews.llvm.org/D41026
Files:
llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/trunk/test/Transforms/InstCombine/store.ll
Index: llvm/trunk/test/Transforms/InstCombine/store.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/store.ll
+++ llvm/trunk/test/Transforms/InstCombine/store.ll
@@ -20,6 +20,14 @@
; CHECK-NEXT: ret void
}
+define void @store_at_gep_off_null(i64 %offset) {
+; CHECK-LABEL: @store_at_gep_off_null
+; CHECK: store i32 undef, i32* %ptr
+ %ptr = getelementptr i32, i32 *null, i64 %offset
+ store i32 24, i32* %ptr
+ ret void
+}
+
;; Simple sinking tests
; "if then else"
Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -959,6 +959,16 @@
return nullptr;
}
+static bool canSimplifyNullStoreOrGEP(StoreInst &SI) {
+ if (SI.getPointerAddressSpace() != 0)
+ return false;
+
+ auto *Ptr = SI.getPointerOperand();
+ if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Ptr))
+ Ptr = GEPI->getOperand(0);
+ return isa<ConstantPointerNull>(Ptr);
+}
+
static bool canSimplifyNullLoadOrGEP(LoadInst &LI, Value *Op) {
if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Op)) {
const Value *GEPI0 = GEPI->getOperand(0);
@@ -1447,7 +1457,8 @@
}
// store X, null -> turns into 'unreachable' in SimplifyCFG
- if (isa<ConstantPointerNull>(Ptr) && SI.getPointerAddressSpace() == 0) {
+ // store X, GEP(null, Y) -> turns into 'unreachable' in SimplifyCFG
+ if (canSimplifyNullStoreOrGEP(SI)) {
if (!isa<UndefValue>(Val)) {
SI.setOperand(0, UndefValue::get(Val->getType()));
if (Instruction *U = dyn_cast<Instruction>(Val))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41026.126539.patch
Type: text/x-patch
Size: 1793 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171212/07c6829d/attachment.bin>
More information about the llvm-commits
mailing list