Skip to content
Closed
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
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6063,7 +6063,7 @@ bool SIInstrInfo::isOperandLegal(const MachineInstr &MI, unsigned OpIdx,
}
} else if (!IsInlineConst && !MO->isReg() && isSALU(MI)) {
// There can be at most one literal operand, but it can be repeated.
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
for (unsigned i = 0, e = MI.getNumExplicitOperands(); i != e; ++i) {
if (i == OpIdx)
continue;
const MachineOperand &Op = MI.getOperand(i);
Expand Down
1 change: 1 addition & 0 deletions llvm/unittests/Target/AMDGPU/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ add_llvm_target_unittest(AMDGPUTests
CSETest.cpp
DwarfRegMappings.cpp
ExecMayBeModifiedBeforeAnyUse.cpp
InstrInfo.cpp
PALMetadata.cpp
)
57 changes: 57 additions & 0 deletions llvm/unittests/Target/AMDGPU/InstrInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//===- llvm/unittests/Target/AMDGPU/ExecMayBeModifiedBeforeAnyUse.cpp -----===//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong file name

//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "AMDGPUTargetMachine.h"
#include "AMDGPUUnitTests.h"
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "gtest/gtest.h"

using namespace llvm;

TEST(AMDGPU, IsOperandLegal) {
auto TM = createAMDGPUTargetMachine("amdgcn-amd-", "gfx1200", "");
if (!TM)
GTEST_SKIP();

GCNSubtarget ST(TM->getTargetTriple(), std::string(TM->getTargetCPU()),
std::string(TM->getTargetFeatureString()), *TM);

LLVMContext Ctx;
Module Mod("Module", Ctx);
Mod.setDataLayout(TM->createDataLayout());

auto *Type = FunctionType::get(Type::getVoidTy(Ctx), false);
auto *F = Function::Create(Type, GlobalValue::ExternalLinkage, "Test", &Mod);

MachineModuleInfo MMI(TM.get());
auto MF =
std::make_unique<MachineFunction>(*F, *TM, ST, MMI.getContext(), 42);
auto *BB = MF->CreateMachineBasicBlock();
MF->push_back(BB);

auto E = BB->end();
DebugLoc DL;
const auto &TII = *ST.getInstrInfo();
const auto &TRI = *ST.getRegisterInfo();
auto &MRI = MF->getRegInfo();

Register VReg = MRI.createVirtualRegister(&AMDGPU::CCR_SGPR_64RegClass);
MachineInstr *Callee =
BuildMI(*BB, E, DL, TII.get(AMDGPU::S_MOV_B64), VReg).addGlobalAddress(F);
MachineInstr *Call =
BuildMI(*BB, E, DL, TII.get(AMDGPU::SI_CALL), AMDGPU::SGPR30_SGPR31)
.addReg(VReg)
.addImm(0)
.addRegMask(TRI.getCallPreservedMask(*MF, CallingConv::AMDGPU_Gfx))
.addReg(AMDGPU::VGPR0, RegState::Implicit)
.addReg(AMDGPU::VGPR1, RegState::Implicit);
Comment on lines +44 to +53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't isOperandLegal get called in the verifier? If you take the MIR here, and put it in test/MachineVerifier does it fail?


// This shouldn't crash.
ASSERT_FALSE(TII.isOperandLegal(*Call, /*OpIdx=*/0, &Callee->getOperand(1)));
}