From 315eafc33980be8a90b16e48bdf551f517b55c48 Mon Sep 17 00:00:00 2001 From: Artur Pilipenko Date: Thu, 25 May 2017 15:14:48 +0000 Subject: [PATCH] [InstCombine] Teach isAllocSiteRemovable to look through addrspacecasts Reviewed By: reames Differential Revision: https://reviews.llvm.org/D28565 llvm-svn: 303870 --- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 4 +++- llvm/test/Transforms/InstCombine/alloca.ll | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 90b024b..2730afc 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1963,6 +1963,7 @@ static bool isAllocSiteRemovable(Instruction *AI, // 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); @@ -2064,7 +2065,8 @@ Instruction *InstCombiner::visitAllocSite(Instruction &MI) { replaceInstUsesWith(*C, ConstantInt::get(Type::getInt1Ty(C->getContext()), C->isFalseWhenEqual())); - } else if (isa(I) || isa(I)) { + } else if (isa(I) || isa(I) || + isa(I)) { replaceInstUsesWith(*I, UndefValue::get(I->getType())); } eraseInstFromFunction(*I); diff --git a/llvm/test/Transforms/InstCombine/alloca.ll b/llvm/test/Transforms/InstCombine/alloca.ll index f81f700..490830a 100644 --- a/llvm/test/Transforms/InstCombine/alloca.ll +++ b/llvm/test/Transforms/InstCombine/alloca.ll @@ -51,8 +51,8 @@ define i32* @test4(i32 %n) { 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 @@ define void @test5() { 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 @@ entry: 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 } -- 2.7.4