Skip to content

Commit af0b0ce

Browse files
authored
[AMDGPU] Fix SIFoldOperandsImpl::tryFoldZeroHighBits when met non-reg src1 operand. (llvm#133761)
This happens when a constant is propagated to a V_AND 0xFFFF, reg instruction. Fixes failures like: ``` llc: /github/llvm-project/llvm/include/llvm/CodeGen/MachineOperand.h:366: llvm::Register llvm::MachineOperand::getReg() const: Assertion `isReg() && "This is not a register operand!"' failed. Stack dump: 0. Program arguments: /github/llvm-project/build/Debug/bin/llc -mtriple=amdgcn -mcpu=gfx1101 -verify-machineinstrs -run-pass si-fold-operands /github/llvm-project/llvm/test/CodeGen/AMDGPU/fold-zero-high-bits-skips-non-reg.mir -o - 1. Running pass 'Function Pass Manager' on module '/github/llvm-project/llvm/test/CodeGen/AMDGPU/fold-zero-high-bits-skips-non-reg.mir'. 2. Running pass 'SI Fold Operands' on function '@test_tryFoldZeroHighBits_skips_nonreg' ... #12 0x00007f5a55005cfc llvm::MachineOperand::getReg() const /github/llvm-project/llvm/include/llvm/CodeGen/MachineOperand.h:0:5 #13 0x00007f5a555c6bf5 (anonymous namespace)::SIFoldOperandsImpl::tryFoldZeroHighBits(llvm::MachineInstr&) const /github/llvm-project/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp:1459:36 #14 0x00007f5a555c63ad (anonymous namespace)::SIFoldOperandsImpl::run(llvm::MachineFunction&) /github/llvm-project/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp:2455:11 #15 0x00007f5a555c6780 (anonymous namespace)::SIFoldOperandsLegacy::runOnMachineFunction ```
1 parent 1cf6786 commit af0b0ce

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: llvm/lib/Target/AMDGPU/SIFoldOperands.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ bool SIFoldOperandsImpl::tryFoldZeroHighBits(MachineInstr &MI) const {
14531453
return false;
14541454

14551455
std::optional<int64_t> Src0Imm = getImmOrMaterializedImm(MI.getOperand(1));
1456-
if (!Src0Imm || *Src0Imm != 0xffff)
1456+
if (!Src0Imm || *Src0Imm != 0xffff || !MI.getOperand(2).isReg())
14571457
return false;
14581458

14591459
Register Src1 = MI.getOperand(2).getReg();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1101 -run-pass si-fold-operands %s -o - | FileCheck %s
3+
---
4+
name: test_tryFoldZeroHighBits_skips_nonreg
5+
tracksRegLiveness: true
6+
body: |
7+
bb.0:
8+
; CHECK-LABEL: name: test_tryFoldZeroHighBits_skips_nonreg
9+
; CHECK: [[V_MOV_B32_e32_:%[0-9]+]]:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
10+
; CHECK-NEXT: [[REG_SEQUENCE:%[0-9]+]]:vreg_64 = REG_SEQUENCE [[V_MOV_B32_e32_]], %subreg.sub0, [[V_MOV_B32_e32_]], %subreg.sub1
11+
; CHECK-NEXT: [[V_AND_B32_e64_:%[0-9]+]]:vgpr_32 = V_AND_B32_e64 65535, 0, implicit $exec
12+
; CHECK-NEXT: S_NOP 0, implicit [[V_AND_B32_e64_]]
13+
%0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
14+
%1:vreg_64 = REG_SEQUENCE %0, %subreg.sub0, %0, %subreg.sub1
15+
%2:vgpr_32 = V_AND_B32_e64 65535, %1.sub0, implicit $exec
16+
S_NOP 0, implicit %2
17+
...

0 commit comments

Comments
 (0)