[openmp] Fix 51647, corrupt bitcode on amdgpu
authordpalermo <Dan.Palermo@amd.com>
Mon, 13 Sep 2021 14:21:21 +0000 (15:21 +0100)
committerJon Chesterfield <jonathanchesterfield@gmail.com>
Mon, 13 Sep 2021 14:24:48 +0000 (15:24 +0100)
commitd5c049a3f68791490e8c87d9974e9831ede0ada0
tree2918de535c6a2e4cc96da276be65808ea4b1859c
parent80b60580dfb6192ac3105e127a82254880b81305
[openmp] Fix 51647, corrupt bitcode on amdgpu

Patch by @dpalermo

The corrupt bitcode reported in https://bugs.llvm.org/show_bug.cgi?id=51647 seems to be a result of a later pass changing the workfn variable to addrspace(5) (thread private, on the stack). That seems reasonable for an alloca without an address space so it's an open question why that can crash the bitcode reader.

This change puts it in the thread private address space to begin with which means whatever misfired further down the pipeline does not break it. That matches the codegen from clang where stack variables are always annotated (5) and then addrspace cast prior to following use.

This therefore patches around whatever unsuccessfully moved the alloca variable to addrspace(5). That solves the problem of openmp opt producing code that crashes the bitcode reader. It should be possible to create a minimal repro for the underlying bug based on some handwritten IR that uses an alloca in a generic address space.

Reviewed By: ronlieb, jdoerfert, dpalermo-phab

Differential Revision: https://reviews.llvm.org/D109500
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
llvm/test/Transforms/OpenMP/custom_state_machines.ll
llvm/test/Transforms/OpenMP/spmdization.ll