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

[PowerPC] crashed at -O1: LLVM ERROR: Found 1 machine code errors.

Open XChy opened this issue 1 year ago • 5 comments

Reproducer: https://godbolt.org/z/dW4Mn4xvv Testcase:

define i32 @func_1(i64 %vecext24) {
entry:
  br label %asm.fallthrough

asm.fallthrough:                                  ; preds = %cond.end, %entry
  %BS_VAR_11.2 = phi i8 [ %conv8, %cond.end ], [ 0, %entry ]
  %conv7 = sext i8 %BS_VAR_11.2 to i32
  %rem = srem i32 %conv7, 7
  %conv8 = trunc i32 %rem to i8
  %cmp.scalar = icmp slt i32 %conv7, 0
  %vecins = insertelement <4 x i16> zeroinitializer, i16 0, i64 %vecext24
  %vecinit26 = insertelement <32 x i8> zeroinitializer, i8 0, i64 0
  %conv58 = sext <32 x i8> %vecinit26 to <32 x i32>
  %vecext59 = extractelement <32 x i32> %conv58, i64 0
  %cmp122 = icmp ult i32 %vecext59, 1
  br i1 %cmp122, label %cond.true, label %cond.end

cond.true:                                        ; preds = %asm.fallthrough
  %vecext124 = extractelement <4 x i16> %vecins, i64 0
  %conv125 = sext i16 %vecext124 to i32
  br label %cond.end

cond.end:                                         ; preds = %cond.true, %asm.fallthrough
  %cond = phi i32 [ %conv125, %cond.true ], [ 1, %asm.fallthrough ]
  store i32 %cond, ptr null, align 4
  br label %asm.fallthrough
}

Output:

LLVM ERROR: Found 1 machine code errors.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -O1 <source>
1.	Running pass 'Function Pass Manager' on module '<source>'.
2.	Running pass 'PowerPC MI Peephole Optimization' on function '@func_1'
 #0 0x00000000040de748 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x40de748)
 #1 0x00000000040db5f4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x000077e66bc42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x000077e66bc969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x000077e66bc42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x000077e66bc287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x00000000007b44ff llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0
 #7 0x000000000311c0af (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x311c0af)
 #8 0x00000000031342b6 llvm::MachineFunction::verify(llvm::Pass*, char const*, llvm::raw_ostream*, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x31342b6)
 #9 0x0000000001c73219 (anonymous namespace)::PPCMIPeephole::runOnMachineFunction(llvm::MachineFunction&) PPCMIPeephole.cpp:0:0
#10 0x0000000002ff7209 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#11 0x000000000362ea98 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x362ea98)
#12 0x000000000362ecd1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x362ecd1)
#13 0x000000000362f53f llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x362f53f)
#14 0x00000000008eafcd compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#15 0x00000000007bc2e6 main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x7bc2e6)
#16 0x000077e66bc29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#17 0x000077e66bc29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#18 0x00000000008e1425 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x8e1425)
Program terminated with signal: SIGSEGV
Compiler returned: 139

XChy avatar Sep 16 '25 15:09 XChy

@llvm/issue-subscribers-backend-powerpc

Author: Hongyu Chen (XChy)

Reproducer: https://godbolt.org/z/dW4Mn4xvv Testcase: ```llvm define i32 @func_1(i64 %vecext24) { entry: br label %asm.fallthrough

asm.fallthrough: ; preds = %cond.end, %entry %BS_VAR_11.2 = phi i8 [ %conv8, %cond.end ], [ 0, %entry ] %conv7 = sext i8 %BS_VAR_11.2 to i32 %rem = srem i32 %conv7, 7 %conv8 = trunc i32 %rem to i8 %cmp.scalar = icmp slt i32 %conv7, 0 %vecins = insertelement <4 x i16> zeroinitializer, i16 0, i64 %vecext24 %vecinit26 = insertelement <32 x i8> zeroinitializer, i8 0, i64 0 %conv58 = sext <32 x i8> %vecinit26 to <32 x i32> %vecext59 = extractelement <32 x i32> %conv58, i64 0 %cmp122 = icmp ult i32 %vecext59, 1 br i1 %cmp122, label %cond.true, label %cond.end

cond.true: ; preds = %asm.fallthrough %vecext124 = extractelement <4 x i16> %vecins, i64 0 %conv125 = sext i16 %vecext124 to i32 br label %cond.end

cond.end: ; preds = %cond.true, %asm.fallthrough %cond = phi i32 [ %conv125, %cond.true ], [ 1, %asm.fallthrough ] store i32 %cond, ptr null, align 4 br label %asm.fallthrough }


Output:

LLVM ERROR: Found 1 machine code errors. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug. Stack dump: 0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -O1 <source>

  1. Running pass 'Function Pass Manager' on module '<source>'.
  2. Running pass 'PowerPC MI Peephole Optimization' on function '@func_1' #0 0x00000000040de748 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x40de748) #1 0x00000000040db5f4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0 #2 0x000077e66bc42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #3 0x000077e66bc969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #4 0x000077e66bc42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #5 0x000077e66bc287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #6 0x00000000007b44ff llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0 #7 0x000000000311c0af (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x311c0af) #8 0x00000000031342b6 llvm::MachineFunction::verify(llvm::Pass*, char const*, llvm::raw_ostream*, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x31342b6) #9 0x0000000001c73219 (anonymous namespace)::PPCMIPeephole::runOnMachineFunction(llvm::MachineFunction&) PPCMIPeephole.cpp:0:0 #10 0x0000000002ff7209 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0 #11 0x000000000362ea98 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x362ea98) #12 0x000000000362ecd1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x362ecd1) #13 0x000000000362f53f llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x362f53f) #14 0x00000000008eafcd compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0 #15 0x00000000007bc2e6 main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x7bc2e6) #16 0x000077e66bc29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #17 0x000077e66bc29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #18 0x00000000008e1425 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x8e1425) Program terminated with signal: SIGSEGV Compiler returned: 139
</details>

llvmbot avatar Sep 16 '25 15:09 llvmbot

I think this is a regression since this compiles on my very old revision. I'll have a look at this when I have some time.

nemanjai avatar Oct 17 '25 06:10 nemanjai

crash on mtriple = powerpc64le-unknown-linux-gnu but not crash on powerpc64-ibm-aix7.2.0.0 and not crash 'powerpc-ibm-aix7.2.0.0` , it looks linux only crash.

diggerlin avatar Nov 27 '25 19:11 diggerlin

A similar testcase: https://godbolt.org/z/W7hKxn6bb

target datalayout = "e-m:e-Fn32-i64:64-i128:128-n32:64-S128-v256:256:256-v512:512:512"
target triple = "powerpc64le-unknown-linux-musl"

define i32 @backsmith_pure_0() {
entry:
  %0 = load i32, ptr null, align 4
  %conv37 = sext i32 %0 to i64
  %1 = insertelement <32 x i64> poison, i64 %conv37, i64 0
  br label %for.cond

for.cond:                                         ; preds = %for.cond, %entry
  %BS_VAR_5.0 = phi <8 x i64> [ zeroinitializer, %entry ], [ %sext, %for.cond ]
  %shuffle = shufflevector <32 x i64> %1, <32 x i64> zeroinitializer, <8 x i32> <i32 0, i32 0, i32 0, i32 32, i32 32, i32 32, i32 40, i32 35>
  %cmp = icmp ugt <8 x i64> %BS_VAR_5.0, %shuffle
  %sext = sext <8 x i1> %cmp to <8 x i64>
  %2 = bitcast <8 x i64> %BS_VAR_5.0 to <64 x i8>
  br label %for.cond
}

XChy avatar Dec 10 '25 08:12 XChy

I posted the following patch to fix these issues: https://github.com/llvm/llvm-project/pull/172122

maryammo avatar Dec 13 '25 02:12 maryammo