| 1 |
//===- llvm/unittests/Target/AMDGPU/ExecMayBeModifiedBeforeAnyUse.cpp -----===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "AMDGPUTargetMachine.h" |
| 10 |
#include "AMDGPUUnitTests.h" |
| 11 |
#include "llvm/CodeGen/MachineModuleInfo.h" |
| 12 |
#include "gtest/gtest.h" |
| 13 |
|
| 14 |
using namespace llvm; |
| 15 |
|
| 16 |
TEST(AMDGPU, ExecMayBeModifiedBeforeAnyUse) { |
| 17 |
auto TM = createAMDGPUTargetMachine("amdgcn-amd-", "gfx906", ""); |
| 18 |
if (!TM) |
| 19 |
return; |
| 20 |
|
| 21 |
GCNSubtarget ST(TM->getTargetTriple(), std::string(TM->getTargetCPU()), |
| 22 |
std::string(TM->getTargetFeatureString()), *TM); |
| 23 |
|
| 24 |
LLVMContext Ctx; |
| 25 |
Module Mod("Module", Ctx); |
| 26 |
Mod.setDataLayout(TM->createDataLayout()); |
| 27 |
|
| 28 |
auto *Type = FunctionType::get(Type::getVoidTy(Ctx), false); |
| 29 |
auto *F = Function::Create(Type, GlobalValue::ExternalLinkage, "Test", &Mod); |
| 30 |
|
| 31 |
MachineModuleInfo MMI(TM.get()); |
| 32 |
auto MF = std::make_unique<MachineFunction>(*F, *TM, ST, 42, MMI); |
| 33 |
auto *BB = MF->CreateMachineBasicBlock(); |
| 34 |
MF->push_back(BB); |
| 35 |
|
| 36 |
auto E = BB->end(); |
| 37 |
DebugLoc DL; |
| 38 |
const auto &TII = *ST.getInstrInfo(); |
| 39 |
auto &MRI = MF->getRegInfo(); |
| 40 |
|
| 41 |
// create machine IR |
| 42 |
Register R = MRI.createVirtualRegister(&AMDGPU::SReg_32RegClass); |
| 43 |
|
| 44 |
MachineInstr *DefMI = |
| 45 |
BuildMI(*BB, E, DL, TII.get(AMDGPU::S_MOV_B32), R).addImm(42).getInstr(); |
| 46 |
|
| 47 |
auto First = |
| 48 |
BuildMI(*BB, E, DL, TII.get(AMDGPU::S_NOP)).addReg(R, RegState::Implicit); |
| 49 |
|
| 50 |
BuildMI(*BB, E, DL, TII.get(AMDGPU::S_NOP)).addReg(R, RegState::Implicit); |
| 51 |
|
| 52 |
// this violates the continuous sequence of R's uses for the first S_NOP |
| 53 |
First.addReg(R, RegState::Implicit); |
| 54 |
|
| 55 |
#ifdef DEBUG_THIS_TEST |
| 56 |
MF->dump(); |
| 57 |
MRI.dumpUses(R); |
| 58 |
#endif |
| 59 |
|
| 60 |
// make sure execMayBeModifiedBeforeAnyUse doesn't crash |
| 61 |
ASSERT_FALSE(execMayBeModifiedBeforeAnyUse(MRI, R, *DefMI)); |
| 62 |
} |