Skip to content

Commit b00bce2

Browse files
committed
[RISCV] Add a test showing an incorrect VSETVLI insertion
This test shows a loop, whose preheader uses a SEW=64, LMUL=1 vector operation. The loop body starts off with another SEW=64, LMUL=1 VADD vector operation, before switching to a SEW=32, LMUL=1/2 vector store instruction. We can see that the VSETVLI insertion pass omits a VSETVLI before the VADD (thinking it inherits its configuration from the preheader) but does place a SEW=32, LMUL=1/2 VSETVLI before the store. This results in a miscompilation as when the loop comes back around, the VADD is incorrectly configured with SEW=32, LMUL=1/2. It appears to be a bad load/store optimization, as replacing the vector store with an SEW=32, LMUL=1/2 VADD does correctly insert a VSETVLI. The issue is therefore possibly arising from canSkipVSETVLIForLoadStore. Differential Revision: https://reviews.llvm.org/D118629
1 parent df3d121 commit b00bce2

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.mir

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@
9595
ret void
9696
}
9797

98+
define void @vsetvli_loop_store() {
99+
ret void
100+
}
101+
98102
; Function Attrs: nounwind readnone
99103
declare <vscale x 1 x i64> @llvm.riscv.vadd.nxv1i64.nxv1i64.i64(<vscale x 1 x i64>, <vscale x 1 x i64>, i64) #1
100104

@@ -527,3 +531,75 @@ body: |
527531
$v0 = COPY %11
528532
PseudoRET implicit $v0
529533
...
534+
---
535+
name: vsetvli_loop_store
536+
tracksRegLiveness: true
537+
registers:
538+
- { id: 0, class: gpr, preferred-register: '' }
539+
- { id: 1, class: gpr, preferred-register: '' }
540+
- { id: 2, class: gpr, preferred-register: '' }
541+
- { id: 3, class: gpr, preferred-register: '' }
542+
- { id: 4, class: vr, preferred-register: '' }
543+
- { id: 5, class: gpr, preferred-register: '' }
544+
- { id: 6, class: gpr, preferred-register: '' }
545+
- { id: 7, class: vr, preferred-register: '' }
546+
- { id: 8, class: gpr, preferred-register: '' }
547+
- { id: 9, class: gpr, preferred-register: '' }
548+
- { id: 10, class: gpr, preferred-register: '' }
549+
body: |
550+
; CHECK-LABEL: name: vsetvli_loop_store
551+
; CHECK: bb.0:
552+
; CHECK-NEXT: successors: %bb.1(0x80000000)
553+
; CHECK-NEXT: liveins: $x10, $x11
554+
; CHECK-NEXT: {{ $}}
555+
; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr = COPY $x10
556+
; CHECK-NEXT: [[PseudoReadVLENB:%[0-9]+]]:gpr = PseudoReadVLENB
557+
; CHECK-NEXT: [[SRLI:%[0-9]+]]:gpr = SRLI [[PseudoReadVLENB]], 3
558+
; CHECK-NEXT: [[COPY1:%[0-9]+]]:gpr = COPY $x11
559+
; CHECK-NEXT: dead %11:gpr = PseudoVSETVLIX0 $x0, 88, implicit-def $vl, implicit-def $vtype
560+
; CHECK-NEXT: [[PseudoVID_V_M1_:%[0-9]+]]:vr = PseudoVID_V_M1 -1, 6, implicit $vl, implicit $vtype
561+
; CHECK-NEXT: [[COPY2:%[0-9]+]]:gpr = COPY $x0
562+
; CHECK-NEXT: {{ $}}
563+
; CHECK-NEXT: bb.1:
564+
; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
565+
; CHECK-NEXT: {{ $}}
566+
; CHECK-NEXT: [[PHI:%[0-9]+]]:gpr = PHI [[COPY2]], %bb.0, %10, %bb.1
567+
; CHECK-NEXT: [[PseudoVADD_VX_M1_:%[0-9]+]]:vr = PseudoVADD_VX_M1 [[PseudoVID_V_M1_]], [[PHI]], -1, 6, implicit $vl, implicit $vtype
568+
; CHECK-NEXT: [[MUL:%[0-9]+]]:gpr = MUL [[PHI]], [[SRLI]]
569+
; CHECK-NEXT: [[ADD:%[0-9]+]]:gpr = ADD [[COPY]], [[MUL]]
570+
; FIXME: We insert a SEW=32,LMUL=1/2 VSETVLI here but no SEW=64,LMUL=1
571+
; VSETVLI before the VADD above. This misconfigures the VADD in the case that
572+
; the loop takes its backedge.
573+
; CHECK-NEXT: dead $x0 = PseudoVSETVLIX0 killed $x0, 87, implicit-def $vl, implicit-def $vtype, implicit $vl
574+
; CHECK-NEXT: PseudoVSE32_V_MF2 killed [[PseudoVADD_VX_M1_]], killed [[ADD]], -1, 5, implicit $vl, implicit $vtype
575+
; CHECK-NEXT: [[ADDI:%[0-9]+]]:gpr = ADDI [[PHI]], 1
576+
; CHECK-NEXT: BLTU [[ADDI]], [[COPY1]], %bb.1
577+
; CHECK-NEXT: PseudoBR %bb.2
578+
; CHECK-NEXT: {{ $}}
579+
; CHECK-NEXT: bb.2:
580+
; CHECK-NEXT: PseudoRET
581+
bb.0:
582+
liveins: $x10, $x11
583+
%0:gpr = COPY $x10
584+
%1:gpr = PseudoReadVLENB
585+
%2:gpr = SRLI %1:gpr, 3
586+
%3:gpr = COPY $x11
587+
%4:vr = PseudoVID_V_M1 -1, 6
588+
%5:gpr = COPY $x0
589+
590+
bb.1:
591+
successors: %bb.1, %bb.2
592+
593+
%6:gpr = PHI %5:gpr, %bb.0, %10:gpr, %bb.1
594+
%7:vr = PseudoVADD_VX_M1 %4:vr, %6:gpr, -1, 6
595+
%8:gpr = MUL %6:gpr, %2:gpr
596+
%9:gpr = ADD %0:gpr, %8:gpr
597+
PseudoVSE32_V_MF2 killed %7:vr, killed %9:gpr, -1, 5
598+
%10:gpr = ADDI %6:gpr, 1
599+
BLTU %10:gpr, %3:gpr, %bb.1
600+
PseudoBR %bb.2
601+
602+
bb.2:
603+
604+
PseudoRET
605+
...

0 commit comments

Comments
 (0)