Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions llvm_passes/HipDynMem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "HipDynMem.h"

#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/IR/Function.h"
Expand All @@ -44,7 +43,6 @@ using namespace llvm;
#define SPIR_LOCAL_AS 3
#define GENERIC_AS 4

typedef llvm::SmallPtrSet<Function *, 16> FSet;
typedef llvm::SetVector<Function *> OrderedFSet;
typedef llvm::SmallVector<GlobalVariable *, 8> GVarVec;

Expand Down Expand Up @@ -91,7 +89,7 @@ class HipDynMemExternReplacePass : public ModulePass {
}
}

static void recursivelyFindDirectUsers(Value *V, FSet &FS) {
static void recursivelyFindDirectUsers(Value *V, OrderedFSet &FS) {
for (auto U : V->users()) {
Instruction *Inst = dyn_cast<Instruction>(U);
if (Inst) {
Expand Down Expand Up @@ -440,7 +438,7 @@ CloneFunctionInto(NewF, F, VV, CloneFunctionChangeType::GlobalChanges, RI);


for (GlobalVariable *GV : GVars) {
FSet DirectUserSet;
OrderedFSet DirectUserSet;

// first, find functions that directly use the GVar. However, these may be
// called from other functions, so we need to append the
Expand Down
2 changes: 2 additions & 0 deletions tests/compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ add_hipcc_test(TestDeviceVirtualFunctions.hip HIPCC_OPTIONS -c)
add_shell_test(TestDeadVTableVirtualBase.bash)
# Program-scope variable init kernels must use their work items (#582).
add_shell_test(TestFix582VarInitWorkItems.bash)
# Lowering a module with many shared memory users must be reproducible (#1661).
add_shell_test(TestFix1661DynMemOrder.bash)
add_hipcc_test(TestHostSideHIPVectors.hip HIPCC_OPTIONS -fsyntax-only)
add_hipcc_test(TestAlignAttr.hip HIPCC_OPTIONS -fsyntax-only)
# Check CHIP_FAST_MATH is set for -ffast-math and preprocessor guards
Expand Down
31 changes: 31 additions & 0 deletions tests/compiler/TestFix1661DynMemOrder.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Regression test for CHIP-SPV/chipStar#1661: lowering a module must not depend
# on allocation addresses, so repeated post-link pipeline runs agree.
set -eu

OPT="@LLVM_TOOLS_BINARY_DIR@/opt"
PLUGIN="@CMAKE_BINARY_DIR@/lib/libLLVMHipSpvPasses.so"
OUT="@CMAKE_CURRENT_BINARY_DIR@/@TEST_NAME@.d"

rm -rf "${OUT}"; mkdir -p "${OUT}"; cd "${OUT}"

# More than 16 users: a small pointer set iterates in insertion order anyway.
{
echo '@__smem = external addrspace(3) global [0 x i32]'
for i in $(seq 32); do
printf 'define spir_kernel void @k%d(i32 %%v) {\n' "${i}"
printf ' store i32 %%v, ptr addrspace(3) @__smem\n ret void\n}\n'
done
} > in.ll

# Heap addresses only change between processes, so compare several runs.
for i in $(seq 8); do
"${OPT}" -load-pass-plugin "${PLUGIN}" -passes=hip-post-link-passes \
in.ll -S -o "run${i}.ll"
if ! cmp -s run1.ll "run${i}.ll"; then
echo "FAIL: run ${i} lowered the same module differently from run 1"
diff run1.ll "run${i}.ll" | head -10
exit 1
fi
done
echo "PASSED"
Loading