Skip to content

Commit

Permalink
[RISCV][VLOPT] Fix passthru check in getOperandInfo (#112244)
Browse files Browse the repository at this point in the history
If a pseudo has a passthru, I believe the first source operand will have
operand no 2, not 1.
  • Loading branch information
lukel97 authored Oct 14, 2024
1 parent 037938d commit db57fc4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 20 deletions.
1 change: 1 addition & 0 deletions llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTarget() {
initializeRISCVPreRAExpandPseudoPass(*PR);
initializeRISCVExpandPseudoPass(*PR);
initializeRISCVVectorPeepholePass(*PR);
initializeRISCVVLOptimizerPass(*PR);
initializeRISCVInsertVSETVLIPass(*PR);
initializeRISCVInsertReadWriteCSRPass(*PR);
initializeRISCVInsertWriteVXRMPass(*PR);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ static OperandInfo getOperandInfo(const MachineInstr &MI,
case RISCV::VWMACCSU_VV:
case RISCV::VWMACCSU_VX:
case RISCV::VWMACCUS_VX: {
bool IsOp1 = HasPassthru ? MO.getOperandNo() == 1 : MO.getOperandNo() == 2;
bool IsOp1 = HasPassthru ? MO.getOperandNo() == 2 : MO.getOperandNo() == 1;
bool TwoTimes = IsMODef || IsOp1;
unsigned Log2EEW = TwoTimes ? MILog2SEW + 1 : MILog2SEW;
RISCVII::VLMUL EMUL =
Expand Down Expand Up @@ -467,7 +467,7 @@ static OperandInfo getOperandInfo(const MachineInstr &MI,
case RISCV::VNCLIP_WI:
case RISCV::VNCLIP_WV:
case RISCV::VNCLIP_WX: {
bool IsOp1 = HasPassthru ? MO.getOperandNo() == 1 : MO.getOperandNo() == 2;
bool IsOp1 = HasPassthru ? MO.getOperandNo() == 2 : MO.getOperandNo() == 1;
bool TwoTimes = IsOp1;
unsigned Log2EEW = TwoTimes ? MILog2SEW + 1 : MILog2SEW;
RISCVII::VLMUL EMUL =
Expand Down
48 changes: 30 additions & 18 deletions llvm/test/CodeGen/RISCV/rvv/vl-opt-op-info.ll
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ declare <vscale x 2 x i16> @llvm.riscv.vnsrl.nxv2i16.nxv2i32.nxv2i16(
iXLen);

define <vscale x 2 x i16> @intrinsic_vnsrl_wv_nxv2i16_nxv2i32_nxv2i16(<vscale x 2 x i16> %a, <vscale x 2 x i16> %b, iXLen %2, <vscale x 2 x i32> %3, <vscale x 2 x i32> %4, <vscale x 2 x i16> %z) nounwind {
; CHECK-LABEL: intrinsic_vnsrl_wv_nxv2i16_nxv2i32_nxv2i16:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: vsetvli a1, zero, e16, mf2, ta, ma
; CHECK-NEXT: vwadd.vv v10, v8, v9
; CHECK-NEXT: vsetvli zero, a0, e16, mf2, ta, ma
; CHECK-NEXT: vnsrl.wv v8, v10, v12
; CHECK-NEXT: ret
; NOVLOPT-LABEL: intrinsic_vnsrl_wv_nxv2i16_nxv2i32_nxv2i16:
; NOVLOPT: # %bb.0: # %entry
; NOVLOPT-NEXT: vsetvli a1, zero, e16, mf2, ta, ma
; NOVLOPT-NEXT: vwadd.vv v10, v8, v9
; NOVLOPT-NEXT: vsetvli zero, a0, e16, mf2, ta, ma
; NOVLOPT-NEXT: vnsrl.wv v8, v10, v12
; NOVLOPT-NEXT: ret
;
; VLOPT-LABEL: intrinsic_vnsrl_wv_nxv2i16_nxv2i32_nxv2i16:
; VLOPT: # %bb.0: # %entry
; VLOPT-NEXT: vsetvli zero, a0, e16, mf2, ta, ma
; VLOPT-NEXT: vwadd.vv v10, v8, v9
; VLOPT-NEXT: vnsrl.wv v8, v10, v12
; VLOPT-NEXT: ret
entry:
%c = sext <vscale x 2 x i16> %a to <vscale x 2 x i32>
%d = sext <vscale x 2 x i16> %b to <vscale x 2 x i32>
Expand All @@ -67,14 +74,22 @@ declare <vscale x 2 x i16> @llvm.riscv.vnclip.nxv2i16.nxv2i32.nxv2i16(
iXLen, iXLen);

define <vscale x 2 x i16> @vnclip(<vscale x 2 x i16> %a, <vscale x 2 x i16> %b, iXLen %2, <vscale x 2 x i32> %3, <vscale x 2 x i32> %4, <vscale x 2 x i16> %z) nounwind {
; CHECK-LABEL: vnclip:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: vsetvli a1, zero, e16, mf2, ta, ma
; CHECK-NEXT: vwadd.vv v10, v8, v9
; CHECK-NEXT: csrwi vxrm, 0
; CHECK-NEXT: vsetvli zero, a0, e16, mf2, ta, ma
; CHECK-NEXT: vnclip.wv v8, v10, v12
; CHECK-NEXT: ret
; NOVLOPT-LABEL: vnclip:
; NOVLOPT: # %bb.0: # %entry
; NOVLOPT-NEXT: vsetvli a1, zero, e16, mf2, ta, ma
; NOVLOPT-NEXT: vwadd.vv v10, v8, v9
; NOVLOPT-NEXT: csrwi vxrm, 0
; NOVLOPT-NEXT: vsetvli zero, a0, e16, mf2, ta, ma
; NOVLOPT-NEXT: vnclip.wv v8, v10, v12
; NOVLOPT-NEXT: ret
;
; VLOPT-LABEL: vnclip:
; VLOPT: # %bb.0: # %entry
; VLOPT-NEXT: vsetvli zero, a0, e16, mf2, ta, ma
; VLOPT-NEXT: vwadd.vv v10, v8, v9
; VLOPT-NEXT: csrwi vxrm, 0
; VLOPT-NEXT: vnclip.wv v8, v10, v12
; VLOPT-NEXT: ret
entry:
%c = sext <vscale x 2 x i16> %a to <vscale x 2 x i32>
%d = sext <vscale x 2 x i16> %b to <vscale x 2 x i32>
Expand All @@ -88,6 +103,3 @@ entry:
ret <vscale x 2 x i16> %x
}

;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; NOVLOPT: {{.*}}
; VLOPT: {{.*}}
18 changes: 18 additions & 0 deletions llvm/test/CodeGen/RISCV/rvv/vl-opt.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
# RUN: llc %s -o - -mtriple=riscv64 -mattr=+v -run-pass=riscv-vl-optimizer -verify-machineinstrs | FileCheck %s

---
name: vnsrl_wv_user
body: |
bb.0:
liveins: $x1
; CHECK-LABEL: name: vnsrl_wv_user
; CHECK: liveins: $x1
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: %vl:gprnox0 = COPY $x1
; CHECK-NEXT: %x:vr = PseudoVADD_VV_MF4 $noreg, $noreg, $noreg, -1, 4 /* e16 */, 0 /* tu, mu */
; CHECK-NEXT: %y:vr = PseudoVNSRL_WV_MF4 $noreg, %x, $noreg, %vl, 4 /* e16 */, 0 /* tu, mu */
%vl:gprnox0 = COPY $x1
%x:vr = PseudoVADD_VV_MF4 $noreg, $noreg, $noreg, -1, 4 /* e16 */, 0 /* tu, mu */
%y:vr = PseudoVNSRL_WV_MF4 $noreg, %x, $noreg, %vl, 4 /* e16 */, 0 /* tu, mu */
...

0 comments on commit db57fc4

Please sign in to comment.