Skip to content

Commit 3fa3932

Browse files
authored
[RISCV] Correct getOperandLog2EEW for VCOMPRESS_VM. (#156719)
The mask operand has EEW=1.
1 parent c5a8841 commit 3fa3932

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,6 @@ getOperandLog2EEW(const MachineOperand &MO, const MachineRegisterInfo *MRI) {
422422
case RISCV::VRGATHER_VI:
423423
case RISCV::VRGATHER_VV:
424424
case RISCV::VRGATHER_VX:
425-
// Vector Compress Instruction
426-
// EEW=SEW.
427-
case RISCV::VCOMPRESS_VM:
428425
// Vector Element Index Instruction
429426
case RISCV::VID_V:
430427
// Vector Single-Width Floating-Point Add/Subtract Instructions
@@ -674,6 +671,12 @@ getOperandLog2EEW(const MachineOperand &MO, const MachineRegisterInfo *MRI) {
674671
return MILog2SEW;
675672
}
676673

674+
// Vector Compress Instruction
675+
// EEW=SEW, except the mask operand has EEW=1. Mask operand is not handled
676+
// before this switch.
677+
case RISCV::VCOMPRESS_VM:
678+
return MO.getOperandNo() == 3 ? 0 : MILog2SEW;
679+
677680
// Vector Iota Instruction
678681
// EEW=SEW, except the mask operand has EEW=1. Mask operand is not handled
679682
// before this switch.

llvm/test/CodeGen/RISCV/rvv/vl-opt.ll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,27 @@ define void @fadd_fcmp_select_copy(<vscale x 4 x float> %v, <vscale x 4 x i1> %c
198198
call void @llvm.riscv.vsm(<vscale x 4 x i1> %select, ptr %p, iXLen %vl)
199199
ret void
200200
}
201+
202+
define <vscale x 8 x i32> @vcompress_cmp(<vscale x 8 x i32> %a, <vscale x 8 x i32> %b, <vscale x 8 x i32> %c, iXLen %vl) {
203+
; CHECK-LABEL: vcompress_cmp:
204+
; CHECK: # %bb.0:
205+
; CHECK-NEXT: vsetvli zero, a0, e32, m4, ta, ma
206+
; CHECK-NEXT: vmseq.vv v20, v8, v12
207+
; CHECK-NEXT: vcompress.vm v8, v16, v20
208+
; CHECK-NEXT: ret
209+
%cmp = icmp eq <vscale x 8 x i32> %a, %b
210+
%compress = call <vscale x 8 x i32> @llvm.riscv.vcompress.nxv8i32(<vscale x 8 x i32> poison, <vscale x 8 x i32> %c, <vscale x 8 x i1> %cmp, iXLen %vl)
211+
ret <vscale x 8 x i32> %compress
212+
}
213+
214+
define <vscale x 8 x i32> @vcompress_add(<vscale x 8 x i32> %a, <vscale x 8 x i32> %b, <vscale x 8 x i1> %c, iXLen %vl) {
215+
; CHECK-LABEL: vcompress_add:
216+
; CHECK: # %bb.0:
217+
; CHECK-NEXT: vsetvli zero, a0, e32, m4, ta, ma
218+
; CHECK-NEXT: vadd.vv v12, v8, v12
219+
; CHECK-NEXT: vcompress.vm v8, v12, v0
220+
; CHECK-NEXT: ret
221+
%add = add <vscale x 8 x i32> %a, %b
222+
%compress = call <vscale x 8 x i32> @llvm.riscv.vcompress.nxv8i32(<vscale x 8 x i32> poison, <vscale x 8 x i32> %add, <vscale x 8 x i1> %c, iXLen %vl)
223+
ret <vscale x 8 x i32> %compress
224+
}

0 commit comments

Comments
 (0)