Skip to content

Commit cdb4da3

Browse files
committed
[NVPTX] Fix failing test and incorrect mcpu reading in reflect
Summary: Test uses nvptx in 32-bit mode and calling `mcpu` is broken and caused asan failures.
1 parent 106f105 commit cdb4da3

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

llvm/lib/Target/NVPTX/NVVMReflect.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ using namespace llvm;
4747

4848
#define DEBUG_TYPE "nvptx-reflect"
4949

50-
namespace llvm { void initializeNVVMReflectPass(PassRegistry &); }
50+
namespace llvm {
51+
void initializeNVVMReflectPass(PassRegistry &);
52+
}
5153

5254
namespace {
5355
class NVVMReflect : public FunctionPass {
@@ -61,15 +63,15 @@ class NVVMReflect : public FunctionPass {
6163

6264
bool runOnFunction(Function &) override;
6365
};
64-
}
66+
} // namespace
6567

6668
FunctionPass *llvm::createNVVMReflectPass(unsigned int SmVersion) {
6769
return new NVVMReflect(SmVersion);
6870
}
6971

7072
static cl::opt<bool>
71-
NVVMReflectEnabled("nvvm-reflect-enable", cl::init(true), cl::Hidden,
72-
cl::desc("NVVM reflection, enabled by default"));
73+
NVVMReflectEnabled("nvvm-reflect-enable", cl::init(true), cl::Hidden,
74+
cl::desc("NVVM reflection, enabled by default"));
7375

7476
char NVVMReflect::ID = 0;
7577
INITIALIZE_PASS(NVVMReflect, "nvvm-reflect",
@@ -189,8 +191,7 @@ static bool runNVVMReflect(Function &F, unsigned SmVersion) {
189191
// until we find a terminator that we can then remove.
190192
while (!ToSimplify.empty()) {
191193
Instruction *I = ToSimplify.pop_back_val();
192-
if (Constant *C =
193-
ConstantFoldInstruction(I, F.getDataLayout())) {
194+
if (Constant *C = ConstantFoldInstruction(I, F.getDataLayout())) {
194195
for (User *U : I->users())
195196
if (Instruction *I = dyn_cast<Instruction>(U))
196197
ToSimplify.push_back(I);
@@ -220,13 +221,7 @@ bool NVVMReflect::runOnFunction(Function &F) {
220221
return runNVVMReflect(F, SmVersion);
221222
}
222223

223-
NVVMReflectPass::NVVMReflectPass() {
224-
// Get the CPU string from the command line if not provided.
225-
std::string MCPU = codegen::getMCPU();
226-
StringRef SM = MCPU;
227-
if (!SM.consume_front("sm_") || SM.consumeInteger(10, SmVersion))
228-
SmVersion = 0;
229-
}
224+
NVVMReflectPass::NVVMReflectPass() {}
230225

231226
PreservedAnalyses NVVMReflectPass::run(Function &F,
232227
FunctionAnalysisManager &AM) {

llvm/test/CodeGen/NVPTX/f32-lg2.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
22
; RUN: llc < %s -mcpu=sm_20 -mattr=+ptx32 | FileCheck --check-prefixes=CHECK %s
33
; RUN: %if ptxas %{ llc < %s -mcpu=sm_20 -mattr=+ptx32 | %ptxas-verify %}
4-
target triple = "nvptx-nvidia-cuda"
4+
target triple = "nvptx64-nvidia-cuda"
55

66
declare float @llvm.nvvm.lg2.approx.f(float)
77
declare float @llvm.nvvm.lg2.approx.ftz.f(float)

llvm/test/CodeGen/NVPTX/nvvm-reflect-arch.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
; Libdevice in recent CUDA versions relies on __CUDA_ARCH reflecting GPU type.
22
; Verify that __nvvm_reflect() is replaced with an appropriate value.
33
;
4-
; RUN: opt %s -S -passes='nvvm-reflect' -mtriple=nvptx64 -mcpu=sm_20 \
4+
; RUN: opt %s -S -passes='default<O2>' -mtriple=nvptx64 -mcpu=sm_20 \
55
; RUN: | FileCheck %s --check-prefixes=COMMON,SM20
6-
; RUN: opt %s -S -passes='nvvm-reflect' -mtriple=nvptx64 -mcpu=sm_35 \
6+
; RUN: opt %s -S -passes='default<O2>' -mtriple=nvptx64 -mcpu=sm_35 \
77
; RUN: | FileCheck %s --check-prefixes=COMMON,SM35
88

99
@"$str" = private addrspace(1) constant [12 x i8] c"__CUDA_ARCH\00"

llvm/test/CodeGen/NVPTX/nvvm-reflect-ocl.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
; Verify that __nvvm_reflect_ocl() is replaced with an appropriate value
22
;
3-
; RUN: opt %s -S -passes='nvvm-reflect' -mtriple=nvptx64 -mcpu=sm_20 \
3+
; RUN: opt %s -S -passes='default<O2>' -mtriple=nvptx64 -mcpu=sm_20 \
44
; RUN: | FileCheck %s --check-prefixes=COMMON,SM20
5-
; RUN: opt %s -S -passes='nvvm-reflect' -mtriple=nvptx64 -mcpu=sm_35 \
5+
; RUN: opt %s -S -passes='default<O2>' -mtriple=nvptx64 -mcpu=sm_35 \
66
; RUN: | FileCheck %s --check-prefixes=COMMON,SM35
77

88
@"$str" = private addrspace(4) constant [12 x i8] c"__CUDA_ARCH\00"

0 commit comments

Comments
 (0)