[PATCH] D47081: Fix evaluator for non-zero alloca addr space

Yaxun Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 18 11:24:35 PDT 2018


yaxunl created this revision.
yaxunl added reviewers: rampitec, arsenm.
Herald added a subscriber: wdng.

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.


https://reviews.llvm.org/D47081

Files:
  lib/Transforms/Utils/Evaluator.cpp
  test/Transforms/GlobalOpt/amdgcn-ctor-alloca.ll


Index: test/Transforms/GlobalOpt/amdgcn-ctor-alloca.ll
===================================================================
--- /dev/null
+++ test/Transforms/GlobalOpt/amdgcn-ctor-alloca.ll
@@ -0,0 +1,14 @@
+; RUN: opt -data-layout=A5 -globalopt %s -S -o - | FileCheck %s
+
+ at g = internal addrspace(1) global i32* 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
+}
+
Index: lib/Transforms/Utils/Evaluator.cpp
===================================================================
--- lib/Transforms/Utils/Evaluator.cpp
+++ lib/Transforms/Utils/Evaluator.cpp
@@ -377,7 +377,8 @@
       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)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47081.147559.patch
Type: text/x-patch
Size: 1411 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180518/809d44a3/attachment.bin>


More information about the llvm-commits mailing list