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

[AArch64] STRXui: Bad machine code: Using an undefined physical register

Open sjoerdmeijer opened this issue 10 months ago • 8 comments

llvm-reduce wasn't able to reduce this further, so am copying the IR reproducer below here for completeness but it is rather large:

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"

@c = external global i32

define i1 @_Z1jiibibcbPcPiPA5_A5_jPA5_A5_sS6_PbPA5_A5_l(i32 %i, i32 %n, i1 %o, ptr %t, ptr %p, ptr %q, ptr %ad, ptr %ae, i16 %conv19, i64 %conv27.us, i16 %conv29, i64 %idxprom79, ptr %arrayidx96, ptr %0, i64 %1, i64 %aq.0212.us.us248.us, <vscale x 16 x i1> %2, ptr %arrayidx118.us.us.us, <vscale x 16 x ptr> %broadcast.splatinsert793, <vscale x 16 x i64> %3, <vscale x 16 x i64> %predphi, i64 %index805, i64 %4, i64 %5, i1 %cmp13) #0 {
entry:
  %6 = sext i32 0 to i64
  br label %for.cond4.preheader

for.cond4.preheader:                              ; preds = %middle.block827, %entry
  br i1 %cmp13, label %for.body18.us, label %for.body45.lr.ph

for.body18.us:                                    ; preds = %for.cond20.for.cond.cleanup22_crit_edge.us, %for.cond4.preheader
  %an.0202.us = phi i32 [ %add33.us, %for.cond20.for.cond.cleanup22_crit_edge.us ], [ %i, %for.cond4.preheader ]
  br label %for.body23.us

for.body23.us:                                    ; preds = %for.body23.us, %for.body18.us
  %ao.0201.us = phi i16 [ %conv19, %for.body18.us ], [ 0, %for.body23.us ]
  store i64 %conv27.us, ptr %t, align 8
  %add.us = or i16 %ao.0201.us, %conv29
  %tobool21.not.us = icmp eq i16 %add.us, 0
  br i1 %tobool21.not.us, label %for.cond20.for.cond.cleanup22_crit_edge.us, label %for.body23.us

for.cond20.for.cond.cleanup22_crit_edge.us:       ; preds = %for.body23.us
  %add33.us = or i32 %an.0202.us, %n
  %tobool.not.us = icmp eq i32 %an.0202.us, 0
  br label %for.body18.us

for.body45.lr.ph:                                 ; preds = %for.cond4.preheader
  %arrayidx98 = getelementptr i32, ptr %arrayidx96, i64 %idxprom79
  br i1 %o, label %for.cond51.preheader.us.us247.us, label %for.cond51.preheader.us.us247

for.cond51.preheader.us.us247.us:                 ; preds = %middle.block827, %for.body45.lr.ph
  %aq.0212.us.us248.us13 = phi i64 [ %add129.us.us250.us, %middle.block827 ], [ 0, %for.body45.lr.ph ]
  %invariant.gep.us.us249.us14 = getelementptr [5 x i32], ptr %q, i64 %aq.0212.us.us248.us13
  %7 = load i32, ptr %arrayidx98, align 4
  %8 = load i16, ptr null, align 2
  %9 = icmp ne i16 %8, 0
  %10 = trunc i32 %7 to i16
  %broadcast.splat790 = shufflevector <vscale x 16 x i1> %2, <vscale x 16 x i1> zeroinitializer, <vscale x 16 x i32> zeroinitializer
  %broadcast.splat794 = shufflevector <vscale x 16 x ptr> %broadcast.splatinsert793, <vscale x 16 x ptr> zeroinitializer, <vscale x 16 x i32> zeroinitializer
  %.scalar1325 = tail call i16 @llvm.umin.i16(i16 1, i16 %10)
  %wide.masked.gather819 = tail call <vscale x 16 x i64> @llvm.masked.gather.nxv16i64.nxv16p0(<vscale x 16 x ptr> %broadcast.splat794, <vscale x 16 x i1> %broadcast.splat790, <vscale x 16 x i64> zeroinitializer)
  br label %vector.body804

vector.body804:                                   ; preds = %vector.body804, %for.cond51.preheader.us.us247.us
  %vec.ind806 = phi <vscale x 16 x i64> [ %3, %for.cond51.preheader.us.us247.us ], [ zeroinitializer, %vector.body804 ]
  %11 = zext <vscale x 16 x i32> zeroinitializer to <vscale x 16 x i64>
  %predphi20 = select i1 %9, <vscale x 16 x i64> %11, <vscale x 16 x i64> zeroinitializer
  %12 = extractelement <vscale x 16 x i64> %predphi, i32 %i
  %13 = getelementptr i8, ptr %0, <vscale x 16 x i64> zeroinitializer
  %wide.masked.gather812 = tail call <vscale x 16 x i8> @llvm.masked.gather.nxv16i8.nxv16p0(<vscale x 16 x ptr> %13, <vscale x 16 x i1> %2, <vscale x 16 x i8> zeroinitializer)
  %14 = extractelement <vscale x 16 x i8> %wide.masked.gather812, i32 1
  %15 = icmp eq i8 %14, 0
  %16 = zext i1 %15 to i64
  tail call void @llvm.masked.scatter.nxv16i64.nxv16p0(<vscale x 16 x i64> splat (i64 -7704966459786987552), <vscale x 16 x ptr> zeroinitializer, <vscale x 16 x i1> %2)
  tail call void @llvm.masked.scatter.nxv16i64.nxv16p0(<vscale x 16 x i64> zeroinitializer, <vscale x 16 x ptr> zeroinitializer, <vscale x 16 x i1> %2)
  tail call void @llvm.masked.scatter.nxv16i64.nxv16p0(<vscale x 16 x i64> zeroinitializer, <vscale x 16 x ptr> zeroinitializer, <vscale x 16 x i1> %2)
  tail call void @llvm.masked.scatter.nxv16i64.nxv16p0(<vscale x 16 x i64> %wide.masked.gather819, <vscale x 16 x ptr> zeroinitializer, <vscale x 16 x i1> %2)
  %17 = getelementptr i8, ptr %ae, <vscale x 16 x i64> %vec.ind806
  %wide.masked.gather821 = tail call <vscale x 16 x i8> @llvm.masked.gather.nxv16i8.nxv16p0(<vscale x 16 x ptr> %17, <vscale x 16 x i1> splat (i1 true), <vscale x 16 x i8> zeroinitializer)
  %wide.masked.gather822 = tail call <vscale x 16 x i8> @llvm.masked.gather.nxv16i8.nxv16p0(<vscale x 16 x ptr> zeroinitializer, <vscale x 16 x i1> %broadcast.splat790, <vscale x 16 x i8> zeroinitializer)
  %18 = zext <vscale x 16 x i8> %wide.masked.gather821 to <vscale x 16 x i32>
  %19 = zext <vscale x 16 x i8> %wide.masked.gather822 to <vscale x 16 x i32>
  tail call void @llvm.masked.scatter.nxv16i32.nxv16p0(<vscale x 16 x i32> %18, <vscale x 16 x ptr> shufflevector (<vscale x 16 x ptr> insertelement (<vscale x 16 x ptr> poison, ptr @c, i64 0), <vscale x 16 x ptr> poison, <vscale x 16 x i32> zeroinitializer), <vscale x 16 x i1> %broadcast.splat790)
  tail call void @llvm.masked.scatter.nxv16i32.nxv16p0(<vscale x 16 x i32> %19, <vscale x 16 x ptr> zeroinitializer, <vscale x 16 x i1> splat (i1 true))
  %index.next825 = add i64 %index805, %4
  %20 = icmp eq i64 %index.next825, 0
  br i1 %20, label %middle.block827, label %vector.body804

middle.block827:                                  ; preds = %vector.body804
  store i64 %12, ptr %p, align 8
  store i64 %16, ptr %t, align 8
  store i16 %.scalar1325, ptr %t, align 2
  %add129.us.us250.us = or i64 %aq.0212.us.us248.us13, 1
  br i1 %o, label %for.cond4.preheader, label %for.cond51.preheader.us.us247.us

for.cond51.preheader.us.us247:                    ; preds = %cond.end.us.us, %for.body45.lr.ph
  br label %for.body55.us213.us

for.body55.us213.us:                              ; preds = %cond.end.us.us, %for.cond51.preheader.us.us247
  %indvars.iv34522 = phi i64 [ %aq.0212.us.us248.us, %cond.end.us.us ], [ %6, %for.cond51.preheader.us.us247 ]
  br i1 %o, label %cond.end.us.us, label %cond.true.us.us

cond.true.us.us:                                  ; preds = %for.body55.us213.us
  %21 = load i32, ptr null, align 4
  br label %cond.end.us.us

cond.end.us.us:                                   ; preds = %cond.true.us.us, %for.body55.us213.us
  store i64 0, ptr %arrayidx118.us.us.us, align 8
  %22 = load i32, ptr %arrayidx98, align 4
  %conv99.us.us = trunc i32 %22 to i16
  %.sroa.speculated189.us.us = tail call i16 @llvm.umin.i16(i16 1, i16 %conv99.us.us)
  store i16 %.sroa.speculated189.us.us, ptr %q, align 2
  store i64 0, ptr %ad, align 8
  store i64 %5, ptr %p, align 8
  %indvars.iv.next346 = or i64 %indvars.iv34522, %1
  %cmp53.us224.us = icmp slt i64 %indvars.iv.next346, %idxprom79
  br i1 %cmp53.us224.us, label %for.body55.us213.us, label %for.cond51.preheader.us.us247
}

; Function Attrs: nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.umin.i16(i16, i16) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(read)
declare <vscale x 16 x i8> @llvm.masked.gather.nxv16i8.nxv16p0(<vscale x 16 x ptr>, <vscale x 16 x i1>, <vscale x 16 x i8>) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(write)
declare void @llvm.masked.scatter.nxv16i64.nxv16p0(<vscale x 16 x i64>, <vscale x 16 x ptr>, <vscale x 16 x i1>) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(read)
declare <vscale x 16 x i64> @llvm.masked.gather.nxv16i64.nxv16p0(<vscale x 16 x ptr>, <vscale x 16 x i1>, <vscale x 16 x i64>) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(write)
declare void @llvm.masked.scatter.nxv16i32.nxv16p0(<vscale x 16 x i32>, <vscale x 16 x ptr>, <vscale x 16 x i1>) #3

; uselistorder directives
uselistorder ptr @llvm.umin.i16, { 1, 0 }
uselistorder ptr @llvm.masked.gather.nxv16i8.nxv16p0, { 2, 1, 0 }
uselistorder ptr @llvm.masked.scatter.nxv16i64.nxv16p0, { 3, 2, 1, 0 }
uselistorder ptr @llvm.masked.scatter.nxv16i32.nxv16p0, { 1, 0 }

attributes #0 = { "target-cpu"="grace" }
attributes #1 = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(read) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(write) }

Compiled with llc -verify-machineinstrs, this runs into the following verifier error:

*** Bad machine code: Using an undefined physical register ***
- function:    _Z1jiibibcbPcPiPA5_A5_jPA5_A5_sS6_PbPA5_A5_l
- basic block: %bb.12 select.end (0x112eaf50)
- instruction: STRXui killed $x8, $sp, 0 :: (store (s64) into %stack.29)
- operand 0:   killed $x8
LLVM ERROR: Found 1 machine code errors.

See also: https://godbolt.org/z/GvcYsGsr4

The reduced fuzzer test-case:

#include <algorithm>
long a, b;
unsigned short d;
int c, f, g;
extern long h[][1][1];
extern long e[][1];
char *ac;
void j(signed i, int n, bool o, int k, bool l, char m, bool s, char t[],
       signed p[], unsigned q[][5][5], short r[][5][5], short ad[][5][5],
       bool ae[], long af[][5][5]) {
  for (int ag;; ag = 1)
    for (short al = 0; al < 5; al = f)
      for (char u; u < (char)n; u = l) {
        for (short am; am < i;)
          for (int an(i); an; an += k)
            for (short ao(s); ao; ao += o)
              a = std::max(short(t[ag]), (short)m);
        for (bool ap(g); ap < (bool)m; ap = l)
          for (long aq(i); aq; aq += 4)
#pragma clang loop vectorize(enable)
            for (int ar(k); ar < m; ar += g + 10) {
              h[u][u][u] =
                  ad[ap][ap][ap] ? std::max(q[ar][aq][ag], q[ag][ag][ag]) : 0;
              a = !ac[ar];
              if (std::max(n, 0)) {
                d = std::min(d, (unsigned short)q[ag][u][u]);
                if (r[aq][aq][1]) {
                  e[u][u] =
                      std::max(10741777613922564064, (unsigned long long)p[u]);
                  b = af[1][1][aq];
                  c = 3 ? -ae[ar] : 0;
                }
              }
            }
      }
}

sjoerdmeijer avatar Jan 27 '26 10:01 sjoerdmeijer

@llvm/issue-subscribers-backend-aarch64

Author: Sjoerd Meijer (sjoerdmeijer)

llvm-reduce wasn't able to reduce this further, so am copying the IR reproducer below here for completeness but it is rather large:
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"

@<!-- -->c = external global i32

define i1 @<!-- -->_Z1jiibibcbPcPiPA5_A5_jPA5_A5_sS6_PbPA5_A5_l(i32 %i, i32 %n, i1 %o, ptr %t, ptr %p, ptr %q, ptr %ad, ptr %ae, i16 %conv19, i64 %conv27.us, i16 %conv29, i64 %idxprom79, ptr %arrayidx96, ptr %0, i64 %1, i64 %aq.0212.us.us248.us, &lt;vscale x 16 x i1&gt; %2, ptr %arrayidx118.us.us.us, &lt;vscale x 16 x ptr&gt; %broadcast.splatinsert793, &lt;vscale x 16 x i64&gt; %3, &lt;vscale x 16 x i64&gt; %predphi, i64 %index805, i64 %4, i64 %5, i1 %cmp13) #<!-- -->0 {
entry:
  %6 = sext i32 0 to i64
  br label %for.cond4.preheader

for.cond4.preheader:                              ; preds = %middle.block827, %entry
  br i1 %cmp13, label %for.body18.us, label %for.body45.lr.ph

for.body18.us:                                    ; preds = %for.cond20.for.cond.cleanup22_crit_edge.us, %for.cond4.preheader
  %an.0202.us = phi i32 [ %add33.us, %for.cond20.for.cond.cleanup22_crit_edge.us ], [ %i, %for.cond4.preheader ]
  br label %for.body23.us

for.body23.us:                                    ; preds = %for.body23.us, %for.body18.us
  %ao.0201.us = phi i16 [ %conv19, %for.body18.us ], [ 0, %for.body23.us ]
  store i64 %conv27.us, ptr %t, align 8
  %add.us = or i16 %ao.0201.us, %conv29
  %tobool21.not.us = icmp eq i16 %add.us, 0
  br i1 %tobool21.not.us, label %for.cond20.for.cond.cleanup22_crit_edge.us, label %for.body23.us

for.cond20.for.cond.cleanup22_crit_edge.us:       ; preds = %for.body23.us
  %add33.us = or i32 %an.0202.us, %n
  %tobool.not.us = icmp eq i32 %an.0202.us, 0
  br label %for.body18.us

for.body45.lr.ph:                                 ; preds = %for.cond4.preheader
  %arrayidx98 = getelementptr i32, ptr %arrayidx96, i64 %idxprom79
  br i1 %o, label %for.cond51.preheader.us.us247.us, label %for.cond51.preheader.us.us247

for.cond51.preheader.us.us247.us:                 ; preds = %middle.block827, %for.body45.lr.ph
  %aq.0212.us.us248.us13 = phi i64 [ %add129.us.us250.us, %middle.block827 ], [ 0, %for.body45.lr.ph ]
  %invariant.gep.us.us249.us14 = getelementptr [5 x i32], ptr %q, i64 %aq.0212.us.us248.us13
  %7 = load i32, ptr %arrayidx98, align 4
  %8 = load i16, ptr null, align 2
  %9 = icmp ne i16 %8, 0
  %10 = trunc i32 %7 to i16
  %broadcast.splat790 = shufflevector &lt;vscale x 16 x i1&gt; %2, &lt;vscale x 16 x i1&gt; zeroinitializer, &lt;vscale x 16 x i32&gt; zeroinitializer
  %broadcast.splat794 = shufflevector &lt;vscale x 16 x ptr&gt; %broadcast.splatinsert793, &lt;vscale x 16 x ptr&gt; zeroinitializer, &lt;vscale x 16 x i32&gt; zeroinitializer
  %.scalar1325 = tail call i16 @<!-- -->llvm.umin.i16(i16 1, i16 %10)
  %wide.masked.gather819 = tail call &lt;vscale x 16 x i64&gt; @<!-- -->llvm.masked.gather.nxv16i64.nxv16p0(&lt;vscale x 16 x ptr&gt; %broadcast.splat794, &lt;vscale x 16 x i1&gt; %broadcast.splat790, &lt;vscale x 16 x i64&gt; zeroinitializer)
  br label %vector.body804

vector.body804:                                   ; preds = %vector.body804, %for.cond51.preheader.us.us247.us
  %vec.ind806 = phi &lt;vscale x 16 x i64&gt; [ %3, %for.cond51.preheader.us.us247.us ], [ zeroinitializer, %vector.body804 ]
  %11 = zext &lt;vscale x 16 x i32&gt; zeroinitializer to &lt;vscale x 16 x i64&gt;
  %predphi20 = select i1 %9, &lt;vscale x 16 x i64&gt; %11, &lt;vscale x 16 x i64&gt; zeroinitializer
  %12 = extractelement &lt;vscale x 16 x i64&gt; %predphi, i32 %i
  %13 = getelementptr i8, ptr %0, &lt;vscale x 16 x i64&gt; zeroinitializer
  %wide.masked.gather812 = tail call &lt;vscale x 16 x i8&gt; @<!-- -->llvm.masked.gather.nxv16i8.nxv16p0(&lt;vscale x 16 x ptr&gt; %13, &lt;vscale x 16 x i1&gt; %2, &lt;vscale x 16 x i8&gt; zeroinitializer)
  %14 = extractelement &lt;vscale x 16 x i8&gt; %wide.masked.gather812, i32 1
  %15 = icmp eq i8 %14, 0
  %16 = zext i1 %15 to i64
  tail call void @<!-- -->llvm.masked.scatter.nxv16i64.nxv16p0(&lt;vscale x 16 x i64&gt; splat (i64 -7704966459786987552), &lt;vscale x 16 x ptr&gt; zeroinitializer, &lt;vscale x 16 x i1&gt; %2)
  tail call void @<!-- -->llvm.masked.scatter.nxv16i64.nxv16p0(&lt;vscale x 16 x i64&gt; zeroinitializer, &lt;vscale x 16 x ptr&gt; zeroinitializer, &lt;vscale x 16 x i1&gt; %2)
  tail call void @<!-- -->llvm.masked.scatter.nxv16i64.nxv16p0(&lt;vscale x 16 x i64&gt; zeroinitializer, &lt;vscale x 16 x ptr&gt; zeroinitializer, &lt;vscale x 16 x i1&gt; %2)
  tail call void @<!-- -->llvm.masked.scatter.nxv16i64.nxv16p0(&lt;vscale x 16 x i64&gt; %wide.masked.gather819, &lt;vscale x 16 x ptr&gt; zeroinitializer, &lt;vscale x 16 x i1&gt; %2)
  %17 = getelementptr i8, ptr %ae, &lt;vscale x 16 x i64&gt; %vec.ind806
  %wide.masked.gather821 = tail call &lt;vscale x 16 x i8&gt; @<!-- -->llvm.masked.gather.nxv16i8.nxv16p0(&lt;vscale x 16 x ptr&gt; %17, &lt;vscale x 16 x i1&gt; splat (i1 true), &lt;vscale x 16 x i8&gt; zeroinitializer)
  %wide.masked.gather822 = tail call &lt;vscale x 16 x i8&gt; @<!-- -->llvm.masked.gather.nxv16i8.nxv16p0(&lt;vscale x 16 x ptr&gt; zeroinitializer, &lt;vscale x 16 x i1&gt; %broadcast.splat790, &lt;vscale x 16 x i8&gt; zeroinitializer)
  %18 = zext &lt;vscale x 16 x i8&gt; %wide.masked.gather821 to &lt;vscale x 16 x i32&gt;
  %19 = zext &lt;vscale x 16 x i8&gt; %wide.masked.gather822 to &lt;vscale x 16 x i32&gt;
  tail call void @<!-- -->llvm.masked.scatter.nxv16i32.nxv16p0(&lt;vscale x 16 x i32&gt; %18, &lt;vscale x 16 x ptr&gt; shufflevector (&lt;vscale x 16 x ptr&gt; insertelement (&lt;vscale x 16 x ptr&gt; poison, ptr @<!-- -->c, i64 0), &lt;vscale x 16 x ptr&gt; poison, &lt;vscale x 16 x i32&gt; zeroinitializer), &lt;vscale x 16 x i1&gt; %broadcast.splat790)
  tail call void @<!-- -->llvm.masked.scatter.nxv16i32.nxv16p0(&lt;vscale x 16 x i32&gt; %19, &lt;vscale x 16 x ptr&gt; zeroinitializer, &lt;vscale x 16 x i1&gt; splat (i1 true))
  %index.next825 = add i64 %index805, %4
  %20 = icmp eq i64 %index.next825, 0
  br i1 %20, label %middle.block827, label %vector.body804

middle.block827:                                  ; preds = %vector.body804
  store i64 %12, ptr %p, align 8
  store i64 %16, ptr %t, align 8
  store i16 %.scalar1325, ptr %t, align 2
  %add129.us.us250.us = or i64 %aq.0212.us.us248.us13, 1
  br i1 %o, label %for.cond4.preheader, label %for.cond51.preheader.us.us247.us

for.cond51.preheader.us.us247:                    ; preds = %cond.end.us.us, %for.body45.lr.ph
  br label %for.body55.us213.us

for.body55.us213.us:                              ; preds = %cond.end.us.us, %for.cond51.preheader.us.us247
  %indvars.iv34522 = phi i64 [ %aq.0212.us.us248.us, %cond.end.us.us ], [ %6, %for.cond51.preheader.us.us247 ]
  br i1 %o, label %cond.end.us.us, label %cond.true.us.us

cond.true.us.us:                                  ; preds = %for.body55.us213.us
  %21 = load i32, ptr null, align 4
  br label %cond.end.us.us

cond.end.us.us:                                   ; preds = %cond.true.us.us, %for.body55.us213.us
  store i64 0, ptr %arrayidx118.us.us.us, align 8
  %22 = load i32, ptr %arrayidx98, align 4
  %conv99.us.us = trunc i32 %22 to i16
  %.sroa.speculated189.us.us = tail call i16 @<!-- -->llvm.umin.i16(i16 1, i16 %conv99.us.us)
  store i16 %.sroa.speculated189.us.us, ptr %q, align 2
  store i64 0, ptr %ad, align 8
  store i64 %5, ptr %p, align 8
  %indvars.iv.next346 = or i64 %indvars.iv34522, %1
  %cmp53.us224.us = icmp slt i64 %indvars.iv.next346, %idxprom79
  br i1 %cmp53.us224.us, label %for.body55.us213.us, label %for.cond51.preheader.us.us247
}

; Function Attrs: nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @<!-- -->llvm.umin.i16(i16, i16) #<!-- -->1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(read)
declare &lt;vscale x 16 x i8&gt; @<!-- -->llvm.masked.gather.nxv16i8.nxv16p0(&lt;vscale x 16 x ptr&gt;, &lt;vscale x 16 x i1&gt;, &lt;vscale x 16 x i8&gt;) #<!-- -->2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(write)
declare void @<!-- -->llvm.masked.scatter.nxv16i64.nxv16p0(&lt;vscale x 16 x i64&gt;, &lt;vscale x 16 x ptr&gt;, &lt;vscale x 16 x i1&gt;) #<!-- -->3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(read)
declare &lt;vscale x 16 x i64&gt; @<!-- -->llvm.masked.gather.nxv16i64.nxv16p0(&lt;vscale x 16 x ptr&gt;, &lt;vscale x 16 x i1&gt;, &lt;vscale x 16 x i64&gt;) #<!-- -->2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(write)
declare void @<!-- -->llvm.masked.scatter.nxv16i32.nxv16p0(&lt;vscale x 16 x i32&gt;, &lt;vscale x 16 x ptr&gt;, &lt;vscale x 16 x i1&gt;) #<!-- -->3

; uselistorder directives
uselistorder ptr @<!-- -->llvm.umin.i16, { 1, 0 }
uselistorder ptr @<!-- -->llvm.masked.gather.nxv16i8.nxv16p0, { 2, 1, 0 }
uselistorder ptr @<!-- -->llvm.masked.scatter.nxv16i64.nxv16p0, { 3, 2, 1, 0 }
uselistorder ptr @<!-- -->llvm.masked.scatter.nxv16i32.nxv16p0, { 1, 0 }

attributes #<!-- -->0 = { "target-cpu"="grace" }
attributes #<!-- -->1 = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
attributes #<!-- -->2 = { nocallback nofree nosync nounwind willreturn memory(read) }
attributes #<!-- -->3 = { nocallback nofree nosync nounwind willreturn memory(write) }

Compiled with llc -verify-machineinstrs, this runs into the following verifier error:

*** Bad machine code: Using an undefined physical register ***
- function:    _Z1jiibibcbPcPiPA5_A5_jPA5_A5_sS6_PbPA5_A5_l
- basic block: %bb.12 select.end (0x112eaf50)
- instruction: STRXui killed $x8, $sp, 0 :: (store (s64) into %stack.29)
- operand 0:   killed $x8
LLVM ERROR: Found 1 machine code errors.

See also: https://godbolt.org/z/GvcYsGsr4

The reduced fuzzer test-case:

#include &lt;algorithm&gt;
long a, b;
unsigned short d;
int c, f, g;
extern long h[][1][1];
extern long e[][1];
char *ac;
void j(signed i, int n, bool o, int k, bool l, char m, bool s, char t[],
       signed p[], unsigned q[][5][5], short r[][5][5], short ad[][5][5],
       bool ae[], long af[][5][5]) {
  for (int ag;; ag = 1)
    for (short al = 0; al &lt; 5; al = f)
      for (char u; u &lt; (char)n; u = l) {
        for (short am; am &lt; i;)
          for (int an(i); an; an += k)
            for (short ao(s); ao; ao += o)
              a = std::max(short(t[ag]), (short)m);
        for (bool ap(g); ap &lt; (bool)m; ap = l)
          for (long aq(i); aq; aq += 4)
#pragma clang loop vectorize(enable)
            for (int ar(k); ar &lt; m; ar += g + 10) {
              h[u][u][u] =
                  ad[ap][ap][ap] ? std::max(q[ar][aq][ag], q[ag][ag][ag]) : 0;
              a = !ac[ar];
              if (std::max(n, 0)) {
                d = std::min(d, (unsigned short)q[ag][u][u]);
                if (r[aq][aq][1]) {
                  e[u][u] =
                      std::max(10741777613922564064, (unsigned long long)p[u]);
                  b = af[1][1][aq];
                  c = 3 ? -ae[ar] : 0;
                }
              }
            }
      }
}

llvmbot avatar Jan 27 '26 10:01 llvmbot

@llvm/issue-subscribers-bug

Author: Sjoerd Meijer (sjoerdmeijer)

llvm-reduce wasn't able to reduce this further, so am copying the IR reproducer below here for completeness but it is rather large:
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"

@<!-- -->c = external global i32

define i1 @<!-- -->_Z1jiibibcbPcPiPA5_A5_jPA5_A5_sS6_PbPA5_A5_l(i32 %i, i32 %n, i1 %o, ptr %t, ptr %p, ptr %q, ptr %ad, ptr %ae, i16 %conv19, i64 %conv27.us, i16 %conv29, i64 %idxprom79, ptr %arrayidx96, ptr %0, i64 %1, i64 %aq.0212.us.us248.us, &lt;vscale x 16 x i1&gt; %2, ptr %arrayidx118.us.us.us, &lt;vscale x 16 x ptr&gt; %broadcast.splatinsert793, &lt;vscale x 16 x i64&gt; %3, &lt;vscale x 16 x i64&gt; %predphi, i64 %index805, i64 %4, i64 %5, i1 %cmp13) #<!-- -->0 {
entry:
  %6 = sext i32 0 to i64
  br label %for.cond4.preheader

for.cond4.preheader:                              ; preds = %middle.block827, %entry
  br i1 %cmp13, label %for.body18.us, label %for.body45.lr.ph

for.body18.us:                                    ; preds = %for.cond20.for.cond.cleanup22_crit_edge.us, %for.cond4.preheader
  %an.0202.us = phi i32 [ %add33.us, %for.cond20.for.cond.cleanup22_crit_edge.us ], [ %i, %for.cond4.preheader ]
  br label %for.body23.us

for.body23.us:                                    ; preds = %for.body23.us, %for.body18.us
  %ao.0201.us = phi i16 [ %conv19, %for.body18.us ], [ 0, %for.body23.us ]
  store i64 %conv27.us, ptr %t, align 8
  %add.us = or i16 %ao.0201.us, %conv29
  %tobool21.not.us = icmp eq i16 %add.us, 0
  br i1 %tobool21.not.us, label %for.cond20.for.cond.cleanup22_crit_edge.us, label %for.body23.us

for.cond20.for.cond.cleanup22_crit_edge.us:       ; preds = %for.body23.us
  %add33.us = or i32 %an.0202.us, %n
  %tobool.not.us = icmp eq i32 %an.0202.us, 0
  br label %for.body18.us

for.body45.lr.ph:                                 ; preds = %for.cond4.preheader
  %arrayidx98 = getelementptr i32, ptr %arrayidx96, i64 %idxprom79
  br i1 %o, label %for.cond51.preheader.us.us247.us, label %for.cond51.preheader.us.us247

for.cond51.preheader.us.us247.us:                 ; preds = %middle.block827, %for.body45.lr.ph
  %aq.0212.us.us248.us13 = phi i64 [ %add129.us.us250.us, %middle.block827 ], [ 0, %for.body45.lr.ph ]
  %invariant.gep.us.us249.us14 = getelementptr [5 x i32], ptr %q, i64 %aq.0212.us.us248.us13
  %7 = load i32, ptr %arrayidx98, align 4
  %8 = load i16, ptr null, align 2
  %9 = icmp ne i16 %8, 0
  %10 = trunc i32 %7 to i16
  %broadcast.splat790 = shufflevector &lt;vscale x 16 x i1&gt; %2, &lt;vscale x 16 x i1&gt; zeroinitializer, &lt;vscale x 16 x i32&gt; zeroinitializer
  %broadcast.splat794 = shufflevector &lt;vscale x 16 x ptr&gt; %broadcast.splatinsert793, &lt;vscale x 16 x ptr&gt; zeroinitializer, &lt;vscale x 16 x i32&gt; zeroinitializer
  %.scalar1325 = tail call i16 @<!-- -->llvm.umin.i16(i16 1, i16 %10)
  %wide.masked.gather819 = tail call &lt;vscale x 16 x i64&gt; @<!-- -->llvm.masked.gather.nxv16i64.nxv16p0(&lt;vscale x 16 x ptr&gt; %broadcast.splat794, &lt;vscale x 16 x i1&gt; %broadcast.splat790, &lt;vscale x 16 x i64&gt; zeroinitializer)
  br label %vector.body804

vector.body804:                                   ; preds = %vector.body804, %for.cond51.preheader.us.us247.us
  %vec.ind806 = phi &lt;vscale x 16 x i64&gt; [ %3, %for.cond51.preheader.us.us247.us ], [ zeroinitializer, %vector.body804 ]
  %11 = zext &lt;vscale x 16 x i32&gt; zeroinitializer to &lt;vscale x 16 x i64&gt;
  %predphi20 = select i1 %9, &lt;vscale x 16 x i64&gt; %11, &lt;vscale x 16 x i64&gt; zeroinitializer
  %12 = extractelement &lt;vscale x 16 x i64&gt; %predphi, i32 %i
  %13 = getelementptr i8, ptr %0, &lt;vscale x 16 x i64&gt; zeroinitializer
  %wide.masked.gather812 = tail call &lt;vscale x 16 x i8&gt; @<!-- -->llvm.masked.gather.nxv16i8.nxv16p0(&lt;vscale x 16 x ptr&gt; %13, &lt;vscale x 16 x i1&gt; %2, &lt;vscale x 16 x i8&gt; zeroinitializer)
  %14 = extractelement &lt;vscale x 16 x i8&gt; %wide.masked.gather812, i32 1
  %15 = icmp eq i8 %14, 0
  %16 = zext i1 %15 to i64
  tail call void @<!-- -->llvm.masked.scatter.nxv16i64.nxv16p0(&lt;vscale x 16 x i64&gt; splat (i64 -7704966459786987552), &lt;vscale x 16 x ptr&gt; zeroinitializer, &lt;vscale x 16 x i1&gt; %2)
  tail call void @<!-- -->llvm.masked.scatter.nxv16i64.nxv16p0(&lt;vscale x 16 x i64&gt; zeroinitializer, &lt;vscale x 16 x ptr&gt; zeroinitializer, &lt;vscale x 16 x i1&gt; %2)
  tail call void @<!-- -->llvm.masked.scatter.nxv16i64.nxv16p0(&lt;vscale x 16 x i64&gt; zeroinitializer, &lt;vscale x 16 x ptr&gt; zeroinitializer, &lt;vscale x 16 x i1&gt; %2)
  tail call void @<!-- -->llvm.masked.scatter.nxv16i64.nxv16p0(&lt;vscale x 16 x i64&gt; %wide.masked.gather819, &lt;vscale x 16 x ptr&gt; zeroinitializer, &lt;vscale x 16 x i1&gt; %2)
  %17 = getelementptr i8, ptr %ae, &lt;vscale x 16 x i64&gt; %vec.ind806
  %wide.masked.gather821 = tail call &lt;vscale x 16 x i8&gt; @<!-- -->llvm.masked.gather.nxv16i8.nxv16p0(&lt;vscale x 16 x ptr&gt; %17, &lt;vscale x 16 x i1&gt; splat (i1 true), &lt;vscale x 16 x i8&gt; zeroinitializer)
  %wide.masked.gather822 = tail call &lt;vscale x 16 x i8&gt; @<!-- -->llvm.masked.gather.nxv16i8.nxv16p0(&lt;vscale x 16 x ptr&gt; zeroinitializer, &lt;vscale x 16 x i1&gt; %broadcast.splat790, &lt;vscale x 16 x i8&gt; zeroinitializer)
  %18 = zext &lt;vscale x 16 x i8&gt; %wide.masked.gather821 to &lt;vscale x 16 x i32&gt;
  %19 = zext &lt;vscale x 16 x i8&gt; %wide.masked.gather822 to &lt;vscale x 16 x i32&gt;
  tail call void @<!-- -->llvm.masked.scatter.nxv16i32.nxv16p0(&lt;vscale x 16 x i32&gt; %18, &lt;vscale x 16 x ptr&gt; shufflevector (&lt;vscale x 16 x ptr&gt; insertelement (&lt;vscale x 16 x ptr&gt; poison, ptr @<!-- -->c, i64 0), &lt;vscale x 16 x ptr&gt; poison, &lt;vscale x 16 x i32&gt; zeroinitializer), &lt;vscale x 16 x i1&gt; %broadcast.splat790)
  tail call void @<!-- -->llvm.masked.scatter.nxv16i32.nxv16p0(&lt;vscale x 16 x i32&gt; %19, &lt;vscale x 16 x ptr&gt; zeroinitializer, &lt;vscale x 16 x i1&gt; splat (i1 true))
  %index.next825 = add i64 %index805, %4
  %20 = icmp eq i64 %index.next825, 0
  br i1 %20, label %middle.block827, label %vector.body804

middle.block827:                                  ; preds = %vector.body804
  store i64 %12, ptr %p, align 8
  store i64 %16, ptr %t, align 8
  store i16 %.scalar1325, ptr %t, align 2
  %add129.us.us250.us = or i64 %aq.0212.us.us248.us13, 1
  br i1 %o, label %for.cond4.preheader, label %for.cond51.preheader.us.us247.us

for.cond51.preheader.us.us247:                    ; preds = %cond.end.us.us, %for.body45.lr.ph
  br label %for.body55.us213.us

for.body55.us213.us:                              ; preds = %cond.end.us.us, %for.cond51.preheader.us.us247
  %indvars.iv34522 = phi i64 [ %aq.0212.us.us248.us, %cond.end.us.us ], [ %6, %for.cond51.preheader.us.us247 ]
  br i1 %o, label %cond.end.us.us, label %cond.true.us.us

cond.true.us.us:                                  ; preds = %for.body55.us213.us
  %21 = load i32, ptr null, align 4
  br label %cond.end.us.us

cond.end.us.us:                                   ; preds = %cond.true.us.us, %for.body55.us213.us
  store i64 0, ptr %arrayidx118.us.us.us, align 8
  %22 = load i32, ptr %arrayidx98, align 4
  %conv99.us.us = trunc i32 %22 to i16
  %.sroa.speculated189.us.us = tail call i16 @<!-- -->llvm.umin.i16(i16 1, i16 %conv99.us.us)
  store i16 %.sroa.speculated189.us.us, ptr %q, align 2
  store i64 0, ptr %ad, align 8
  store i64 %5, ptr %p, align 8
  %indvars.iv.next346 = or i64 %indvars.iv34522, %1
  %cmp53.us224.us = icmp slt i64 %indvars.iv.next346, %idxprom79
  br i1 %cmp53.us224.us, label %for.body55.us213.us, label %for.cond51.preheader.us.us247
}

; Function Attrs: nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @<!-- -->llvm.umin.i16(i16, i16) #<!-- -->1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(read)
declare &lt;vscale x 16 x i8&gt; @<!-- -->llvm.masked.gather.nxv16i8.nxv16p0(&lt;vscale x 16 x ptr&gt;, &lt;vscale x 16 x i1&gt;, &lt;vscale x 16 x i8&gt;) #<!-- -->2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(write)
declare void @<!-- -->llvm.masked.scatter.nxv16i64.nxv16p0(&lt;vscale x 16 x i64&gt;, &lt;vscale x 16 x ptr&gt;, &lt;vscale x 16 x i1&gt;) #<!-- -->3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(read)
declare &lt;vscale x 16 x i64&gt; @<!-- -->llvm.masked.gather.nxv16i64.nxv16p0(&lt;vscale x 16 x ptr&gt;, &lt;vscale x 16 x i1&gt;, &lt;vscale x 16 x i64&gt;) #<!-- -->2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(write)
declare void @<!-- -->llvm.masked.scatter.nxv16i32.nxv16p0(&lt;vscale x 16 x i32&gt;, &lt;vscale x 16 x ptr&gt;, &lt;vscale x 16 x i1&gt;) #<!-- -->3

; uselistorder directives
uselistorder ptr @<!-- -->llvm.umin.i16, { 1, 0 }
uselistorder ptr @<!-- -->llvm.masked.gather.nxv16i8.nxv16p0, { 2, 1, 0 }
uselistorder ptr @<!-- -->llvm.masked.scatter.nxv16i64.nxv16p0, { 3, 2, 1, 0 }
uselistorder ptr @<!-- -->llvm.masked.scatter.nxv16i32.nxv16p0, { 1, 0 }

attributes #<!-- -->0 = { "target-cpu"="grace" }
attributes #<!-- -->1 = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
attributes #<!-- -->2 = { nocallback nofree nosync nounwind willreturn memory(read) }
attributes #<!-- -->3 = { nocallback nofree nosync nounwind willreturn memory(write) }

Compiled with llc -verify-machineinstrs, this runs into the following verifier error:

*** Bad machine code: Using an undefined physical register ***
- function:    _Z1jiibibcbPcPiPA5_A5_jPA5_A5_sS6_PbPA5_A5_l
- basic block: %bb.12 select.end (0x112eaf50)
- instruction: STRXui killed $x8, $sp, 0 :: (store (s64) into %stack.29)
- operand 0:   killed $x8
LLVM ERROR: Found 1 machine code errors.

See also: https://godbolt.org/z/GvcYsGsr4

The reduced fuzzer test-case:

#include &lt;algorithm&gt;
long a, b;
unsigned short d;
int c, f, g;
extern long h[][1][1];
extern long e[][1];
char *ac;
void j(signed i, int n, bool o, int k, bool l, char m, bool s, char t[],
       signed p[], unsigned q[][5][5], short r[][5][5], short ad[][5][5],
       bool ae[], long af[][5][5]) {
  for (int ag;; ag = 1)
    for (short al = 0; al &lt; 5; al = f)
      for (char u; u &lt; (char)n; u = l) {
        for (short am; am &lt; i;)
          for (int an(i); an; an += k)
            for (short ao(s); ao; ao += o)
              a = std::max(short(t[ag]), (short)m);
        for (bool ap(g); ap &lt; (bool)m; ap = l)
          for (long aq(i); aq; aq += 4)
#pragma clang loop vectorize(enable)
            for (int ar(k); ar &lt; m; ar += g + 10) {
              h[u][u][u] =
                  ad[ap][ap][ap] ? std::max(q[ar][aq][ag], q[ag][ag][ag]) : 0;
              a = !ac[ar];
              if (std::max(n, 0)) {
                d = std::min(d, (unsigned short)q[ag][u][u]);
                if (r[aq][aq][1]) {
                  e[u][u] =
                      std::max(10741777613922564064, (unsigned long long)p[u]);
                  b = af[1][1][aq];
                  c = 3 ? -ae[ar] : 0;
                }
              }
            }
      }
}

llvmbot avatar Jan 27 '26 10:01 llvmbot

Hi - do you have the original code for this? Thanks

davemgreen avatar Feb 23 '26 17:02 davemgreen

Sorry for the late reply, @davemgreen, but the source code reproducer is in the original message, all the way at the bottom. I've just quickly checked, and it is still segfaulting.

sjoerdmeijer avatar Mar 09 '26 11:03 sjoerdmeijer

Hi - this came from another team. In their parlance they were wondering whether this was a translation fault or just a compiler assert. Presumably the original came from a fuzzer and would show whether it produced an invalid hash or not? That would help them figure out one way or another.

I'm assuming you don't have the original pre-reduced code or the hash it came from? Thanks.

davemgreen avatar Mar 09 '26 13:03 davemgreen

Oh, I see. I have looked and don't have the pre-reduced code anymore. I did hit this again last weekend, but deleted that result too as a duplicate of this thing, so also don't have that one anymore. I am sure this will come up again though.

This was reported as a compile time error. Sometimes I use a build with extensive checks and asserts enabled, and that build ran into this assert. So, it is definitely not an invalid hash producing or runtime problem.

sjoerdmeijer avatar Mar 09 '26 15:03 sjoerdmeijer

David, Sjoerd, do you know if this is safety-related (or safety-affecting)?

MarkMurrayARM avatar Mar 19 '26 09:03 MarkMurrayARM

No longer crashing on trunk. Also doesn't reproduce on 22 (https://godbolt.org/z/dWo5v5faa) and this was reported only 2 weeks after the branch so it must have been introduced sometime between then. Bisect points at #143073 introducing crash, but that seems unlikely so perhaps it just exposed it. Not sure what commit it stopped crashing

c-rhodes avatar Jul 16 '26 14:07 c-rhodes