Skip to content

[PPC] Invalid PPC CTR loop! with powerpcspe #55463

@DimitryAndric

Description

@DimitryAndric

After upgrading the FreeBSD base system with llvm 14.0.3, I started seeing errors with the powerpcspe builds:

Invalid PPC CTR loop!
UNREACHABLE executed at /usr/src/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCCTRLoops.cpp:179!
PLEASE submit a bug report to https://bugs.freebsd.org/submit/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: clang -cc1 -triple powerpcspe-unknown-freebsd14.0 -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -main-file-name gdtoa_dtoa.c -mrelocation-model static -mframe-pointer=none -relaxed-aliasing -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu e500 -target-feature +spe -target-feature +secure-plt -mfloat-abi hard -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=gdb -fcoverage-compilation-dir=/home/dim/obj/home/dim/src/main/powerpc.powerpcspe/lib/libc -sys-header-deps -D NO__SCCSID -D NO__RCSID -D NLS -D __DBINTERFACE_PRIVATE -D INET6 -D _ACL_PRIVATE -D POSIX_MISTAKE -D BROKEN_DES -D PORTMAP -D DES_BUILTIN -D YP -D NS_CACHING -D SYMBOL_VERSIONING -O2 -Wno-format-zero-length -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable -Wno-error=unused-but-set-variable -Wno-tautological-compare -Wno-unused-value -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion -Wno-unused-local-typedef -Wno-address-of-packed-member -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter -w -std=gnu99 -fdebug-compilation-dir=/home/dim/obj/home/dim/src/main/powerpc.powerpcspe/lib/libc -ferror-limit 19 -ftls-model=initial-exec -stack-protector 2 -fno-signed-char -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c gdtoa_dtoa-88928c.c
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'gdtoa_dtoa-88928c.c'.
4.      Running pass 'PowerPC CTR Loops Verify' on function '@__dtoa'

This turns out to still be a problem with very recent main (26c82f3 is the last I tried).

Reduced test case (C version):

// clang -cc1 -triple powerpcspe-- -S -ffp-contract=on -target-feature +spe -O2 gdtoa_dtoa-min.c
typedef struct {
  int d;
} U;
int __dtoa_i;
U __dtoa_d;
double __dtoa_ds;
void __dtoa() {
  for (;; __dtoa_i++) {
    (&__dtoa_d)->d -= 0 * __dtoa_ds;
    if (__dtoa_i == 1)
      break;
  }
}

.ll version:

; ModuleID = 'gdtoa_dtoa-min.c'
source_filename = "gdtoa_dtoa-min.c"
target datalayout = "E-m:e-p:32:32-i64:64-n32"
target triple = "powerpcspe-unknown-unknown"

%struct.U = type { i32 }

@__dtoa_d = external local_unnamed_addr global %struct.U, align 4

define dso_local void @__dtoa() local_unnamed_addr #0 {
entry:
  br label %for.inc

for.inc:                                          ; preds = %for.inc, %entry
  %conv17 = phi i32 [ %conv1, %for.inc ], [ undef, %entry ]
  %0 = phi i32 [ %inc, %for.inc ], [ undef, %entry ]
  %inc = add nsw i32 %0, 1
  %conv = sitofp i32 %conv17 to double
  %1 = tail call double @llvm.fmuladd.f64(double 0.000000e+00, double -0.000000e+00, double %conv)
  %conv1 = fptosi double %1 to i32
  %cmp = icmp eq i32 %0, 0
  br i1 %cmp, label %for.cond.for.end_crit_edge, label %for.inc

for.cond.for.end_crit_edge:                       ; preds = %for.inc
  store i32 %conv1, i32* getelementptr inbounds (%struct.U, %struct.U* @__dtoa_d, i32 0, i32 0), align 4
  ret void
}

; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
declare double @llvm.fmuladd.f64(double, double, double) #1

attributes #0 = { "target-features"="+spe,-altivec,-bpermd,-crypto,-direct-move,-extdiv,-htm,-isa-v206-instructions,-isa-v207-instructions,-isa-v30-instructions,-power8-vector,-power9-vector,-privileged,-rop-protect,-vsx" }
attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions