[llvm] r332794 - Fix evaluator for non-zero alloca addr space
Yaxun Liu via llvm-commits
llvm-commits at lists.llvm.org
Fri May 18 19:58:16 PDT 2018
Author: yaxunl
Date: Fri May 18 19:58:16 2018
New Revision: 332794
URL: http://llvm.org/viewvc/llvm-project?rev=332794&view=rev
Log:
Fix evaluator for non-zero alloca addr space
The evaluator goes through BB and creates global vars as temporary values to evaluate
results of LLVM instructions. It creates undef for alloca, however it assumes alloca
in addr space 0. If the next instruction is addrspace cast to 0, then we get an invalid
cast instruction.
This patch let the temp global var have an address space matching alloca addr space,
so that the valuation can be done.
Differential Revision: https://reviews.llvm.org/D47081
Added:
llvm/trunk/test/Transforms/GlobalOpt/amdgcn-ctor-alloca.ll
Modified:
llvm/trunk/lib/Transforms/Utils/Evaluator.cpp
Modified: llvm/trunk/lib/Transforms/Utils/Evaluator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Evaluator.cpp?rev=332794&r1=332793&r2=332794&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Evaluator.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Evaluator.cpp Fri May 18 19:58:16 2018
@@ -377,7 +377,8 @@ bool Evaluator::EvaluateBlock(BasicBlock
Type *Ty = AI->getAllocatedType();
AllocaTmps.push_back(llvm::make_unique<GlobalVariable>(
Ty, false, GlobalValue::InternalLinkage, UndefValue::get(Ty),
- AI->getName()));
+ AI->getName(), /*TLMode=*/GlobalValue::NotThreadLocal,
+ AI->getType()->getPointerAddressSpace()));
InstResult = AllocaTmps.back().get();
LLVM_DEBUG(dbgs() << "Found an alloca. Result: " << *InstResult << "\n");
} else if (isa<CallInst>(CurInst) || isa<InvokeInst>(CurInst)) {
Added: llvm/trunk/test/Transforms/GlobalOpt/amdgcn-ctor-alloca.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/amdgcn-ctor-alloca.ll?rev=332794&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/amdgcn-ctor-alloca.ll (added)
+++ llvm/trunk/test/Transforms/GlobalOpt/amdgcn-ctor-alloca.ll Fri May 18 19:58:16 2018
@@ -0,0 +1,17 @@
+; RUN: opt -data-layout=A5 -globalopt %s -S -o - | FileCheck %s
+
+; CHECK-NOT: @g
+ at g = internal addrspace(1) global i32* zeroinitializer
+
+; CHECK: @llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }] zeroinitializer
+ at llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }]
+ [{ i32, void ()*, i8* } { i32 65535, void ()* @ctor, i8* null }]
+
+; CHECK-NOT: @ctor
+define internal void @ctor() {
+ %addr = alloca i32, align 8, addrspace(5)
+ %tmp = addrspacecast i32 addrspace(5)* %addr to i32*
+ store i32* %tmp, i32* addrspace(1)* @g
+ ret void
+}
+
More information about the llvm-commits
mailing list