[PATCH] D28565: Teach isAllocSiteRemovable to look through addrspacecasts
Artur Pilipenko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 11 07:14:25 PST 2017
apilipenko created this revision.
apilipenko added reviewers: nlopes, hfinkel, reames.
apilipenko added a subscriber: llvm-commits.
https://reviews.llvm.org/D28565
Files:
lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/alloca.ll
Index: test/Transforms/InstCombine/alloca.ll
===================================================================
--- test/Transforms/InstCombine/alloca.ll
+++ test/Transforms/InstCombine/alloca.ll
@@ -51,8 +51,8 @@
ret i32* %A
}
-; Allocas which are only used by GEPs, bitcasts, and stores (transitively)
-; should be deleted.
+; Allocas which are only used by GEPs, bitcasts, addrspacecasts, and stores
+; (transitively) should be deleted.
define void @test5() {
; CHECK-LABEL: @test5(
; CHECK-NOT: alloca
@@ -62,6 +62,7 @@
entry:
%a = alloca { i32 }
%b = alloca i32*
+ %c = alloca i32
%a.1 = getelementptr { i32 }, { i32 }* %a, i32 0, i32 0
store i32 123, i32* %a.1
store i32* %a.1, i32** %b
@@ -73,6 +74,8 @@
store atomic i32 3, i32* %a.3 release, align 4
%a.4 = getelementptr { i32 }, { i32 }* %a, i32 0, i32 0
store atomic i32 4, i32* %a.4 seq_cst, align 4
+ %c.1 = addrspacecast i32* %c to i32 addrspace(1)*
+ store i32 123, i32 addrspace(1)* %c.1
ret void
}
Index: lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- lib/Transforms/InstCombine/InstructionCombining.cpp
+++ lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1944,6 +1944,7 @@
// Give up the moment we see something we can't handle.
return false;
+ case Instruction::AddrSpaceCast:
case Instruction::BitCast:
case Instruction::GetElementPtr:
Users.emplace_back(I);
@@ -2045,7 +2046,8 @@
replaceInstUsesWith(*C,
ConstantInt::get(Type::getInt1Ty(C->getContext()),
C->isFalseWhenEqual()));
- } else if (isa<BitCastInst>(I) || isa<GetElementPtrInst>(I)) {
+ } else if (isa<BitCastInst>(I) || isa<GetElementPtrInst>(I) ||
+ isa<AddrSpaceCastInst>(I)) {
replaceInstUsesWith(*I, UndefValue::get(I->getType()));
}
eraseInstFromFunction(*I);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28565.83974.patch
Type: text/x-patch
Size: 2006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170111/a6d58b2c/attachment.bin>
More information about the llvm-commits
mailing list