Skip to content

Commit cbbc7e4

Browse files
committed
llvm-reduce: Don't set generic instruction operands to undef
The intention is that these should never have undef operands. It turns out the restriction the verifier enforces is too lax. The verifier enforces that registers without a register class cannot be undef, but it's valid to use a register with a register class and type. The verifier needs to change to be based on the opcode.
1 parent 47c8ec8 commit cbbc7e4

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

llvm/test/tools/llvm-reduce/mir/generic-vreg.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# REQUIRES: amdgpu-registered-target
2-
# RUN: llvm-reduce -mtriple=amdgcn-amd-amdhsa --test FileCheck --test-arg --check-prefix=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t 2> %t.log
2+
# RUN: llvm-reduce -abort-on-invalid-reduction -mtriple=amdgcn-amd-amdhsa --test FileCheck --test-arg --check-prefix=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t 2> %t.log
33
# RUN: FileCheck --match-full-lines --check-prefix=RESULT %s < %t
44

55
# Verify that reduction works with generic virtual registers, and the
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# REQUIRES: amdgpu-registered-target
2+
# RUN: llvm-reduce -abort-on-invalid-reduction -simplify-mir --delta-passes=register-uses -mtriple=amdgcn-amd-amdhsa --test FileCheck --test-arg --check-prefix=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t 2> %t.log
3+
# RUN: FileCheck --match-full-lines --check-prefix=RESULT %s < %t
4+
5+
# Generic instructions should not have undef set on operands
6+
# CHECK-INTERESTINGNESS: G_ADD
7+
8+
# RESULT: %1:vreg_64(s64) = IMPLICIT_DEF
9+
# RESULT: %add:_(s64) = G_ADD %1, %1
10+
11+
---
12+
name: func
13+
tracksRegLiveness: true
14+
body: |
15+
bb.0:
16+
liveins: $vgpr0, $vgpr1, $vgpr2_vgpr3
17+
18+
%0:vgpr(s32) = G_IMPLICIT_DEF
19+
%1:vreg_64(s64) = IMPLICIT_DEF
20+
%add:_(s64) = G_ADD %1, %1
21+
%ptr:_(p1) = G_IMPLICIT_DEF
22+
G_STORE %0(s32), %ptr(p1) :: (store (s32), addrspace 1)
23+
S_ENDPGM 0, implicit %add(s64), implicit %1(s64)
24+
25+
...

llvm/tools/llvm-reduce/deltas/ReduceRegisterUses.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ static void removeUsesFromFunction(Oracle &O, MachineFunction &MF) {
2222

2323
for (MachineBasicBlock &MBB : MF) {
2424
for (MachineInstr &MI : MBB) {
25+
// Generic instructions are not supposed to have undef operands.
26+
if (isPreISelGenericOpcode(MI.getOpcode()))
27+
continue;
28+
2529
int NumOperands = MI.getNumOperands();
2630
int NumRequiredOps = MI.getNumExplicitOperands() +
2731
MI.getDesc().getNumImplicitDefs() +

0 commit comments

Comments
 (0)