Skip to content

Commit 7c46482

Browse files
committed
[RISCV][VLOPT] Fix passthru check in getOperandInfo
If a pseudo has a passthru, I believe the first source operand will be the second operand, not the first. I've added an MIR test which should show how we're reading the wrong SEW, but in order to be able to use -run-pass=riscv-vl-optimizer I needed to initialize the pass in RISCVTargetMachine.cpp.
1 parent 200c330 commit 7c46482

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTarget() {
128128
initializeRISCVPreRAExpandPseudoPass(*PR);
129129
initializeRISCVExpandPseudoPass(*PR);
130130
initializeRISCVVectorPeepholePass(*PR);
131+
initializeRISCVVLOptimizerPass(*PR);
131132
initializeRISCVInsertVSETVLIPass(*PR);
132133
initializeRISCVInsertReadWriteCSRPass(*PR);
133134
initializeRISCVInsertWriteVXRMPass(*PR);

llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static OperandInfo getOperandInfo(const MachineInstr &MI,
431431
case RISCV::VWMACCSU_VV:
432432
case RISCV::VWMACCSU_VX:
433433
case RISCV::VWMACCUS_VX: {
434-
bool IsOp1 = HasPassthru ? MO.getOperandNo() == 1 : MO.getOperandNo() == 2;
434+
bool IsOp1 = HasPassthru ? MO.getOperandNo() == 2 : MO.getOperandNo() == 1;
435435
bool TwoTimes = IsMODef || IsOp1;
436436
unsigned Log2EEW = TwoTimes ? MILog2SEW + 1 : MILog2SEW;
437437
RISCVII::VLMUL EMUL =
@@ -467,7 +467,7 @@ static OperandInfo getOperandInfo(const MachineInstr &MI,
467467
case RISCV::VNCLIP_WI:
468468
case RISCV::VNCLIP_WV:
469469
case RISCV::VNCLIP_WX: {
470-
bool IsOp1 = HasPassthru ? MO.getOperandNo() == 1 : MO.getOperandNo() == 2;
470+
bool IsOp1 = HasPassthru ? MO.getOperandNo() == 2 : MO.getOperandNo() == 1;
471471
bool TwoTimes = IsOp1;
472472
unsigned Log2EEW = TwoTimes ? MILog2SEW + 1 : MILog2SEW;
473473
RISCVII::VLMUL EMUL =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ body: |
1010
; CHECK: liveins: $x1
1111
; CHECK-NEXT: {{ $}}
1212
; CHECK-NEXT: %vl:gprnox0 = COPY $x1
13-
; CHECK-NEXT: %x:vr = PseudoVADD_VV_MF4 $noreg, $noreg, $noreg, %vl, 4 /* e16 */, 0 /* tu, mu */
13+
; CHECK-NEXT: %x:vr = PseudoVADD_VV_MF4 $noreg, $noreg, $noreg, -1, 4 /* e16 */, 0 /* tu, mu */
1414
; CHECK-NEXT: %y:vr = PseudoVNSRL_WV_MF4 $noreg, %x, $noreg, %vl, 4 /* e16 */, 0 /* tu, mu */
1515
%vl:gprnox0 = COPY $x1
1616
%x:vr = PseudoVADD_VV_MF4 $noreg, $noreg, $noreg, -1, 4 /* e16 */, 0 /* tu, mu */

0 commit comments

Comments
 (0)