Skip to content

[AMDGPU] si-peephole-sdwa: Disable V_CNDMASK_B32 conversion with sext #140760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 15 additions & 0 deletions llvm/lib/Target/AMDGPU/SIPeepholeSDWA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,21 @@ bool SDWASrcOperand::convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII) {
case AMDGPU::V_CVT_PK_F32_BF8_sdwa:
// Does not support input modifiers: noabs, noneg, nosext.
return false;
case AMDGPU::V_CNDMASK_B32_sdwa:
// SISrcMods uses the same bitmask for SEXT and NEG modifiers and
// hence the compiler can only support one type of modifier for
// each SDWA instruction. For V_CNDMASK_B32_sdwa, this is NEG
// since its operands get printed using
// AMDGPUInstPrinter::printOperandAndFPInputMods which produces
// the output intended for NEG if SEXT is set.
//
// The ISA does actually support both modifiers on most SDWA
// instructions.
//
// FIXME Accept SEXT here after fixing this issue.
if (Sext)
return false;
break;
}

// Find operand in instruction that matches source operand and replace it with
Expand Down
21 changes: 21 additions & 0 deletions llvm/test/CodeGen/AMDGPU/sdwa-peephole-cndmask-sext.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 < %s | FileCheck %s
; XFAIL: *

; FIXME The sext modifier is turned into a neg modifier in the asm output

define i32 @test_select_on_sext_sdwa(i8 %x, i32 %y, i1 %cond) {
; CHECK-LABEL: test_select_on_sext_sdwa:
; CHECK: ; %bb.0:
; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
; CHECK-NEXT: v_and_b32_e32 v2, 1, v2
; CHECK-NEXT: v_cmp_eq_u32_e32 vcc, 1, v2
; CHECK-NEXT: v_mov_b32_e32 v2, 0
; CHECK-NEXT: s_nop 0
; CHECK-NEXT: v_cndmask_b32_sdwa v0, v2, sext(v0), vcc dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:DWORD src1_sel:BYTE_0
; CHECK-NEXT: v_or_b32_e32 v0, v0, v1
; CHECK-NEXT: s_setpc_b64 s[30:31]
%sext = sext i8 %x to i32
%select = select i1 %cond, i32 %sext, i32 zeroinitializer
%or = or i32 %select, %y
ret i32 %or
}