Skip to content

Commit 4568a24

Browse files
committed
pr feedback
Signed-off-by: Nathan Gauër <[email protected]>
1 parent 1b8d488 commit 4568a24

File tree

6 files changed

+46
-8
lines changed

6 files changed

+46
-8
lines changed

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,9 +2278,9 @@ class TargetInstrInfo : public MCInstrInfo {
22782278
llvm_unreachable("unknown number of operands necessary");
22792279
}
22802280

2281-
// This this instruction a PHI node.
2281+
// Returns true if this instruction is a PHI node.
22822282
// This function should be favored over MI.isPHI() as it allows backends to
2283-
// define additional PHI instructions.
2283+
// report actual PHI instructions in their ISA as such.
22842284
virtual bool isPhiInstr(const MachineInstr &MI) const {
22852285
return MI.getOpcode() == TargetOpcode::G_PHI ||
22862286
MI.getOpcode() == TargetOpcode::PHI;
@@ -2292,7 +2292,7 @@ class TargetInstrInfo : public MCInstrInfo {
22922292
assert(isPhiInstr(MI));
22932293
// G_PHI/PHI only have a single operand before the pairs. 2 Operands per
22942294
// pair.
2295-
return (MI.getNumOperands() - 1) / 2;
2295+
return (MI.getNumOperands() - 1) >> 1;
22962296
}
22972297

22982298
// Returns the |index|'th [Value, Src] pair of this phi instruction.

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,8 +3242,8 @@ void MachineVerifier::calcRegsRequired() {
32423242

32433243
// Handle the PHI nodes.
32443244
// Note: MBB.phis() only returns range containing PHI/G_PHI instructions.
3245-
// MachineVerifier checks MIR post-ISel, and some backends do have their own
3246-
// phi nodes.
3245+
// MachineVerifier checks MIR post-ISel, and some target ISA can have actual
3246+
// PHI instructions that would be missed in MBB.phis() (e.g. SPIR-V).
32473247
for (const MachineInstr &MI : MBB) {
32483248
// PHI nodes must be the first instructions of the MBB.
32493249
if (!TII->isPhiInstr(MI))

llvm/lib/Target/SPIRV/SPIRVInstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ bool SPIRVInstrInfo::isPhiInstr(const MachineInstr &MI) const {
278278
unsigned SPIRVInstrInfo::getNumPhiIncomingPair(const MachineInstr &MI) const {
279279
// OpPhi has 2 operands before the [Value, Src] pairs.
280280
if (MI.getOpcode() == SPIRV::OpPhi)
281-
return (MI.getNumOperands() - 2) / 2;
281+
return (MI.getNumOperands() - 2) >> 1;
282282
return TargetInstrInfo::getNumPhiIncomingPair(MI);
283283
}
284284

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not "SPIRV" in config.root.targets:
2+
config.unsupported = True
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# RUN: llc -o - %s -mtriple=spirv-unknown-vulkan-compute -run-pass=none | FileCheck %s
2+
# REQUIRES: spirv-registered-target
3+
4+
# This should cleanly pass the machine verifier.
5+
---
6+
# CHECK-LABEL: name: func0
7+
# CHECK: %7:id = OpPhi %1, %5, %bb.1, %6, %bb.2
8+
name: func0
9+
tracksRegLiveness: true
10+
noPhis: false
11+
body: |
12+
bb.0:
13+
%0:type = OpTypeBool
14+
%1:type = OpTypeInt 32, 0
15+
%2:iid = OpFunctionParameter %1
16+
%3:iid = OpFunctionParameter %1
17+
%4:iid = OpIEqual %0, %2, %3
18+
OpBranchConditional %4, %bb.1, %bb.2
19+
20+
bb.1:
21+
%5:iid = OpLoad %1, %2
22+
OpBranch %bb.3
23+
24+
bb.2:
25+
%6:iid = OpLoad %1, %3
26+
OpBranch %bb.3
27+
28+
bb.3:
29+
# This test validates a subtle SPIR-V difference with PHI nodes:
30+
# It is valid to have the same predecessor present twice in the instruction,
31+
# as long as the associated value is the same.
32+
%7:id = OpPhi %1, %5, %bb.1, %6, %bb.2, %5, %bb.1
33+
...
34+
---

llvm/test/MachineVerifier/verifier-phi-spirv.mir renamed to llvm/test/MachineVerifier/SPIRV/verifier-phi.mir

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# RUN: llc -o - %s -mtriple=spirv-unknown-vulkan-compute -verify-machineinstrs -run-pass=none | FileCheck %s
1+
# RUN: llc -o - %s -mtriple=spirv-unknown-vulkan-compute -run-pass=none | FileCheck %s
22
# REQUIRES: spirv-registered-target
33

4-
# This should cleanly pass the machine verifier
4+
# This should cleanly pass the machine verifier.
5+
# Nothing specific regarding PHI requirements, just a slight change in
6+
# the operand list vs G_PHI.
57
---
68
# CHECK-LABEL: name: func0
79
# CHECK: %7:id = OpPhi %1, %5, %bb.1, %6, %bb.2

0 commit comments

Comments
 (0)