Issue 68120
Summary LLVM 17.x fails to build AdaptiveCpp for AMDGPU due to `invalid addrspacecast`
Labels backend:AMDGPU, new issue
Assignees
Reporter fodinabor
    For any of the current LLVM 17.x releases, [AdaptiveCpp](https://github.com/AdaptiveCpp/AdaptiveCpp) (hipSYCL) fails to build its test suit for AMDGPU, independent of the used ROCm version with the error `invalid addrspacecast`.
This can be found e.g. in the CI here: https://github.com/fodinabor/hipSYCL-LLVM-upstream-ci/actions/runs/6381943553/job/17319482716#step:12:569

I didn't take a closer look a the IR, yet.
[LLVM 16](https://github.com/AdaptiveCpp/AdaptiveCpp/actions/runs/6343017764/job/17229994676#step:14:14) and [upstream LLVM](https://github.com/fodinabor/hipSYCL-LLVM-upstream-ci/actions/runs/6378018187/job/17307792193) are fine.

I bisected both LLVM 16-17 and LLVM 17-main:
the first bad commit is: https://github.com/llvm/llvm-project/commit/72fc08a5412ec7ee7f0b904926db16cd86c1f876
the first good-again commit is: https://github.com/llvm/llvm-project/commit/d77c62053c944652846c00a35c921e14b43b1877

Applying d77c62053c944652846c00a35c921e14b43b1877 to `release/17.x` solves the issue, but not sure that's something we want to backport since it changes ABI..?

See the following scripts for reproducing it:
```bash
#!/bin/bash

# Use local dir as workdir
export WORKDIR=`pwd`

# Set ccache size to 512GB and use /tmp/ccache as the cache directory
export CCACHE_MAXSIZE=512G
export CCACHE_DIR=/tmp/ccache

# Clone the AdaptiveCpp repo
git clone https://github.com/AdaptiveCpp/AdaptiveCpp.git acpp

# Clone the llvm-project repository
git clone https://github.com/llvm/llvm-project.git

# Change into the llvm-project directory
cd llvm-project

# Start the bisect process
git bisect start

# Specify the good and bad commits
# git bisect old llvmorg-18-init
# git bisect new main
git bisect old llvmorg-17-init
git bisect new llvmorg-18-init

# Write a script to test the build
# This script should exit with code 0 if the build is successful
# and a non-zero code if the build fails
# For example:
# ./build_and_test.sh

# Run the bisect process
git bisect run ~/build_and_test.sh

# Once the bisect process is complete, reset the repository to the original state
git bisect reset
```

build_and_test.sh
```bash
#!/bin/bash

rm -r $WORKDIR/install/*

mkdir -p build
cd build
cmake -G Ninja ../llvm -DLLVM_ENABLE_PROJECTS="clang;compiler-rt;lld;openmp" \
 -DOPENMP_ENABLE_LIBOMPTARGET=OFF \
 -DCMAKE_BUILD_TYPE=Release \
 -DCMAKE_INSTALL_PREFIX=$WORKDIR/install/llvm \
 -DLLVM_ENABLE_ASSERTIONS=OFF \
 -DLLVM_TARGETS_TO_BUILD="X86;AMDGPU" \
 -DCLANG_ANALYZER_ENABLE_Z3_SOLVER=0 \
 -DLLVM_INCLUDE_BENCHMARKS=0 \
 -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \
 -DCMAKE_INSTALL_RPATH=$WORKDIR/install/llvm/lib \
 -DLLVM_ENABLE_OCAMLDOC=OFF \
               -DLLVM_ENABLE_BINDINGS=OFF \
               -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=OFF \
 -DLLVM_ENABLE_DUMP=OFF \
 -DLLVM_CCACHE_BUILD=ON
if [ $? -ne 0 ]; then
    echo "LLVM CMake failed"
    exit 125
fi

ninja -j $OMP_NUM_THREADS install
if [ $? -ne 0 ]; then
    echo "LLVM install failed"
    exit 125
fi

cd $WORKDIR/acpp
rm -r build tests/build
mkdir -p build
cd build

cmake -G Ninja .. \
 -DCMAKE_BUILD_TYPE=Release \
 -DCMAKE_INSTALL_PREFIX=$WORKDIR/install/acpp \
 -DLLVM_DIR=$WORKDIR/install/llvm/lib/cmake/llvm \
 -DWITH_ROCM_BACKEND=ON \
    -DWITH_CUDA_BACKEND=OFF \
 -DWITH_OPENCL_BACKEND=OFF \
    -DWITH_SSCP_COMPILER=OFF \
 -DWITH_STDPAR_COMPILER=OFF 
if [ $? -ne 0 ]; then
    echo "AdaptiveCpp CMake failed"
    exit 125
fi

ninja -j $OMP_NUM_THREADS install
if [ $? -ne 0 ]; then
    echo "Buliding AdaptiveCpp failed"
    exit 125
fi

cd $WORKDIR/acpp/tests
mkdir -p build
cd build
cmake -G Ninja .. \
 -DCMAKE_BUILD_TYPE=Release \
 -DAdaptiveCpp_DIR=$WORKDIR/install/acpp/lib/cmake/AdaptiveCpp \
 -DACPP_TARGETS="hip:gfx906"
if [ $? -ne 0 ]; then
    echo "AdaptiveCpp Tests CMake failed"
    exit 125
fi

ninja -j $OMP_NUM_THREADS |& tee build.log
if grep -q "error: invalid addrspacecast" build.log; then
    echo "AdaptiveCpp Tests build failed due to invalid addrspacecast"
    exit 1
fi
if [ $? -ne 0 ]; then
    echo "AdaptiveCpp Tests build failed"
    exit 125
fi

exit 0
```

cc @illuhad 

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to