From 75cacfb4903fb4530b20773bcd482973e0e7e95d Mon Sep 17 00:00:00 2001 From: Jingyue Wu Date: Tue, 30 Jun 2015 18:59:19 +0000 Subject: [PATCH] [NVPTX] Fix issue introduced in D10321 Summary: Really check if %SP is not used in other places, instead of checking only exact one non-dbg use. Patched by Xuetian Weng. Test Plan: @foo4 in test/CodeGen/NVPTX/local-stack-frame.ll, create a case that SP will appear twice. Reviewers: jholewinski, jingyue Reviewed By: jingyue Subscribers: llvm-commits, sfantao, jholewinski Differential Revision: http://reviews.llvm.org/D10844 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241099 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/NVPTX/NVPTXFrameLowering.cpp | 5 ++--- test/CodeGen/NVPTX/local-stack-frame.ll | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/Target/NVPTX/NVPTXFrameLowering.cpp b/lib/Target/NVPTX/NVPTXFrameLowering.cpp index 0b0cb87e5bc..cffcac0f19f 100644 --- a/lib/Target/NVPTX/NVPTXFrameLowering.cpp +++ b/lib/Target/NVPTX/NVPTXFrameLowering.cpp @@ -47,20 +47,19 @@ void NVPTXFrameLowering::emitPrologue(MachineFunction &MF, // cvta.local %SP, %SPL; if (static_cast(MF.getTarget()).is64Bit()) { // Check if %SP is actually used - if (MR.hasOneNonDBGUse(NVPTX::VRFrame)) { + if (!MR.use_empty(NVPTX::VRFrame)) { MI = BuildMI(MBB, MI, dl, MF.getSubtarget().getInstrInfo()->get( NVPTX::cvta_local_yes_64), NVPTX::VRFrame) .addReg(NVPTX::VRFrameLocal); } - BuildMI(MBB, MI, dl, MF.getSubtarget().getInstrInfo()->get(NVPTX::MOV_DEPOT_ADDR_64), NVPTX::VRFrameLocal) .addImm(MF.getFunctionNumber()); } else { // Check if %SP is actually used - if (MR.hasOneNonDBGUse(NVPTX::VRFrame)) { + if (!MR.use_empty(NVPTX::VRFrame)) { MI = BuildMI(MBB, MI, dl, MF.getSubtarget().getInstrInfo()->get( NVPTX::cvta_local_yes), NVPTX::VRFrame) diff --git a/test/CodeGen/NVPTX/local-stack-frame.ll b/test/CodeGen/NVPTX/local-stack-frame.ll index 1058e4b0a57..fba5dd883f9 100644 --- a/test/CodeGen/NVPTX/local-stack-frame.ll +++ b/test/CodeGen/NVPTX/local-stack-frame.ll @@ -56,3 +56,21 @@ define void @foo3(i32 %a) { store i32 %a, i32* %2 ret void } + +; PTX32: cvta.local.u32 %SP, %SPL; +; PTX32: add.u32 {{%r[0-9]+}}, %SP, 0; +; PTX32: st.local.u32 [{{%r[0-9]+}}], {{%r[0-9]+}} +; PTX32: st.local.u32 [{{%r[0-9]+}}], {{%r[0-9]+}} +; PTX64: cvta.local.u64 %SP, %SPL; +; PTX64: add.u64 {{%rd[0-9]+}}, %SP, 0; +; PTX64: st.local.u32 [{{%rd[0-9]+}}], {{%r[0-9]+}} +; PTX64: st.local.u32 [{{%rd[0-9]+}}], {{%r[0-9]+}} +define void @foo4() { + %A = alloca i32 + %B = alloca i32 + store i32 0, i32* %A + store i32 0, i32* %B + call void @bar(i32* %A) + call void @bar(i32* %B) + ret void +} -- 2.34.1