llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[AArch64][GISel] STRXui "Expected a GPR64 register, but got a GPR64sp register"

Open sjoerdmeijer opened this issue 1 year ago • 3 comments

This is most likely not a minimal reproducer, but this IR:

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "aarch64-unknown-linux-gnu"

define void @_Z4testahhxjjjxjaxti(i1 %cmp599, i1 %cmp15592, ptr %arrayidx207.us, ptr %0, i64 %idxprom264) {
entry:
  br i1 %cmp599, label %for.body.lr.ph, label %for.cond233.preheader

for.body.lr.ph:                                   ; preds = %entry
  br i1 %cmp15592, label %for.body.us.preheader, label %for.body

for.body.us.preheader:                            ; preds = %for.body.lr.ph
  store i64 1866308388, ptr %arrayidx207.us, align 8
  br label %for.cond233.preheader

for.cond233.preheader:                            ; preds = %for.body.us.preheader, %entry
  br i1 %cmp15592, label %for.cond240.preheader.lr.ph.split.us, label %for.body256

for.cond240.preheader.lr.ph.split.us:             ; preds = %for.cond233.preheader
  store i64 1866308389, ptr %arrayidx207.us, align 8
  br label %iter.check

iter.check:                                       ; preds = %for.body295.us.us.us.us.us, %vector.main.loop.iter.check, %for.cond240.preheader.lr.ph.split.us
  %brmerge6 = select i1 false, i1 false, i1 false
  br i1 %cmp15592, label %for.body295.us.us.us.us.us, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %iter.check
  br i1 %cmp599, label %iter.check, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %1 = insertelement <4 x i32> zeroinitializer, i32 0, i64 0
  br label %for.body295.us.us.us.us.us

for.body295.us.us.us.us.us:                       ; preds = %for.body295.us.us.us.us.us, %vector.ph, %iter.check
  br i1 %cmp599, label %for.body295.us.us.us.us.us, label %iter.check

for.body:                                         ; preds = %for.body, %for.body.lr.ph
  br label %for.body

for.body256:                                      ; preds = %for.body256, %for.cond233.preheader
  %arrayidx275 = getelementptr i64, ptr %0, i64 %idxprom264
  store i64 1866308389, ptr %arrayidx275, align 8
  br label %for.body256
}

Triggers this verifier failure:

*** Bad machine code: Illegal virtual register for instruction ***
- function:    _Z4testahhxjjjxjaxti
- basic block: %bb.14 for.body256 (0x35c1cf20)
- instruction: STRXroX %11:gpr64sp, %3:gpr64sp, %4:gpr64, 0, 1 :: (store (s64) into %ir.arrayidx275)
- operand 0:   %11:gpr64sp
Expected a GPR64 register, but got a GPR64sp register

when compiled with llc --verify-machineinstrs -global-isel, see also:

https://godbolt.org/z/a8xYfj48b

sjoerdmeijer avatar Nov 05 '25 12:11 sjoerdmeijer

@llvm/issue-subscribers-backend-aarch64

Author: Sjoerd Meijer (sjoerdmeijer)

This is most likely not a minimal reproducer, but this IR:
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "aarch64-unknown-linux-gnu"

define void @<!-- -->_Z4testahhxjjjxjaxti(i1 %cmp599, i1 %cmp15592, ptr %arrayidx207.us, ptr %0, i64 %idxprom264) {
entry:
  br i1 %cmp599, label %for.body.lr.ph, label %for.cond233.preheader

for.body.lr.ph:                                   ; preds = %entry
  br i1 %cmp15592, label %for.body.us.preheader, label %for.body

for.body.us.preheader:                            ; preds = %for.body.lr.ph
  store i64 1866308388, ptr %arrayidx207.us, align 8
  br label %for.cond233.preheader

for.cond233.preheader:                            ; preds = %for.body.us.preheader, %entry
  br i1 %cmp15592, label %for.cond240.preheader.lr.ph.split.us, label %for.body256

for.cond240.preheader.lr.ph.split.us:             ; preds = %for.cond233.preheader
  store i64 1866308389, ptr %arrayidx207.us, align 8
  br label %iter.check

iter.check:                                       ; preds = %for.body295.us.us.us.us.us, %vector.main.loop.iter.check, %for.cond240.preheader.lr.ph.split.us
  %brmerge6 = select i1 false, i1 false, i1 false
  br i1 %cmp15592, label %for.body295.us.us.us.us.us, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %iter.check
  br i1 %cmp599, label %iter.check, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %1 = insertelement &lt;4 x i32&gt; zeroinitializer, i32 0, i64 0
  br label %for.body295.us.us.us.us.us

for.body295.us.us.us.us.us:                       ; preds = %for.body295.us.us.us.us.us, %vector.ph, %iter.check
  br i1 %cmp599, label %for.body295.us.us.us.us.us, label %iter.check

for.body:                                         ; preds = %for.body, %for.body.lr.ph
  br label %for.body

for.body256:                                      ; preds = %for.body256, %for.cond233.preheader
  %arrayidx275 = getelementptr i64, ptr %0, i64 %idxprom264
  store i64 1866308389, ptr %arrayidx275, align 8
  br label %for.body256
}

Triggers this verifier failure:

*** Bad machine code: Illegal virtual register for instruction ***
- function:    _Z4testahhxjjjxjaxti
- basic block: %bb.14 for.body256 (0x35c1cf20)
- instruction: STRXroX %11:gpr64sp, %3:gpr64sp, %4:gpr64, 0, 1 :: (store (s64) into %ir.arrayidx275)
- operand 0:   %11:gpr64sp
Expected a GPR64 register, but got a GPR64sp register

when compiled with llc --verify-machineinstrs -global-isel, see also:

https://godbolt.org/z/a8xYfj48b

llvmbot avatar Nov 05 '25 12:11 llvmbot

Looks like something weird is going wrong with InstructionSelect, it generates a store with the expected register class:

Erasing:   G_STORE %15:gpr64(s64), %18:gpr(p0) :: (store (s64) into %ir.arrayidx275)
Created:
  STRXroX %15:gpr64(s64), %3:gpr64sp(p0), %4:gpr64(s64), 0, 1 :: (store (s64) into %ir.arrayidx275)

This then turns into

  STRXroX %11:gpr64sp, %3:gpr64sp, %4:gpr64, 0, 1 :: (store (s64) into %ir.arrayidx275)

after the pass finishes running.

EDIT: Assigning myself for now.

dc03-work avatar Nov 27 '25 10:11 dc03-work

I think this is the same issue #166563. The two machine code errors are identical, %11:gpr64sp has wrong register class:

*** Bad machine code: Illegal virtual register for instruction ***
- function:    _Z4testahhxjjjxjaxti
- basic block: %bb.7 for.cond240.preheader.lr.ph.split.us (0xe34ffd0)
- instruction: STRXui %11:gpr64sp, %2:gpr64sp, 0 :: (store (s64) into %ir.arrayidx207.us)
- operand 0:   %11:gpr64sp
Expected a GPR64 register, but got a GPR64sp register

*** Bad machine code: Illegal virtual register for instruction ***
- function:    _Z4testahhxjjjxjaxti
- basic block: %bb.14 for.body256 (0xe350a90)
- instruction: STRXroX %11:gpr64sp, %3:gpr64sp, %4:gpr64, 0, 1 :: (store (s64) into %ir.arrayidx275)
- operand 0:   %11:gpr64sp
Expected a GPR64 register, but got a GPR64sp register
LLVM ERROR: Found 2 machine code errors.

and the operand is materializing a 64-bit constant via MOVi32imm + SUBREG_TO_REG:

  %51:gpr32 = MOVi32imm 1866308389
  %11:gpr64sp = SUBREG_TO_REG 0, %51:gpr32, %subreg.sub_32

c-rhodes avatar Jan 15 '26 16:01 c-rhodes