1 //===- llvm/unittests/Target/AMDGPU/ExecMayBeModifiedBeforeAnyUse.cpp -----===//
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
7 //===----------------------------------------------------------------------===//
9 #include "AMDGPUTargetMachine.h"
10 #include "AMDGPUUnitTests.h"
11 #include "llvm/CodeGen/MachineModuleInfo.h"
12 #include "gtest/gtest.h"
16 TEST(AMDGPU
, ExecMayBeModifiedBeforeAnyUse
) {
17 auto TM
= createAMDGPUTargetMachine("amdgcn-amd-", "gfx906", "");
21 GCNSubtarget
ST(TM
->getTargetTriple(), std::string(TM
->getTargetCPU()),
22 std::string(TM
->getTargetFeatureString()), *TM
);
25 Module
Mod("Module", Ctx
);
26 Mod
.setDataLayout(TM
->createDataLayout());
28 auto *Type
= FunctionType::get(Type::getVoidTy(Ctx
), false);
29 auto *F
= Function::Create(Type
, GlobalValue::ExternalLinkage
, "Test", &Mod
);
31 MachineModuleInfo
MMI(TM
.get());
33 std::make_unique
<MachineFunction
>(*F
, *TM
, ST
, MMI
.getContext(), 42);
34 auto *BB
= MF
->CreateMachineBasicBlock();
39 const auto &TII
= *ST
.getInstrInfo();
40 auto &MRI
= MF
->getRegInfo();
43 Register R
= MRI
.createVirtualRegister(&AMDGPU::SReg_32RegClass
);
46 BuildMI(*BB
, E
, DL
, TII
.get(AMDGPU::S_MOV_B32
), R
).addImm(42).getInstr();
49 BuildMI(*BB
, E
, DL
, TII
.get(AMDGPU::S_NOP
)).addReg(R
, RegState::Implicit
);
51 BuildMI(*BB
, E
, DL
, TII
.get(AMDGPU::S_NOP
)).addReg(R
, RegState::Implicit
);
53 // this violates the continuous sequence of R's uses for the first S_NOP
54 First
.addReg(R
, RegState::Implicit
);
56 #ifdef DEBUG_THIS_TEST
61 // make sure execMayBeModifiedBeforeAnyUse doesn't crash
62 ASSERT_FALSE(execMayBeModifiedBeforeAnyUse(MRI
, R
, *DefMI
));