Skip to content

Not supported instr: <MCInst 237 <MCOperand Reg:42>> (LLVM-85) #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MabezDev opened this issue Jan 17, 2021 · 16 comments
Closed

Not supported instr: <MCInst 237 <MCOperand Reg:42>> (LLVM-85) #43

MabezDev opened this issue Jan 17, 2021 · 16 comments

Comments

@MabezDev
Copy link

I've just been updating the Xtensa Rust fork and I've ran into this issue when building for the esp32 in release mode (haven't yet reproduced on the esp8266).

Compiling core v0.0.0 (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/src/rust/library/core)
LLVM ERROR: Not supported instr: <MCInst 237 <MCOperand Reg:42>>
error: could not compile `core`

Here's the llvm IR: core-e40c46572e76fe97.core.7bmkbcle-cgu.0.rcgu.ll.zip

@kelnos
Copy link

kelnos commented Jan 21, 2021

Ran into this as well with your branch. Tried a few things to see if I could figure out what was going on, with no success:

  1. Merged branch rustc/11.0-2020-10-12 of rust-lang/llvm-project (branch that 1.49.0 uses) into xtensa_release_11.0.0
  2. Merged upstream llvm/llvm-project's 11.x branch into xtensa_release_11.0.0
  3. Attempted to bisect rust itself between 1.48.0 and 1.49.0

The bisect was unfortunately unhelpful, as rust's history between versions isn't linear; the 1.48.0 and 1.49.0 tags don't have much in common wrt commit history, so the bisect wasn't able to come up with anything conclusive. Best it could do ended with:

The merge base 6ebad43c255e63ac0734646fe817de5780d76b45 is bad.
This means the bug has been fixed between 6ebad43c255e63ac0734646fe817de5780d76b45 and [7eac88abb2e57e752f3302f02be5f3ce3d7adfb4].
bisect run failed:
'bisect_state bad' exited with error code 3

Nothing really stood out to me as interesting in the diff between those revisions, but admittedly I'm a rank amateur here, so it's very possible I missed something.

Here's the (somewhat janky) script I used with git bisect run, in case it's useful: test-rust-xtensa-bisect.sh.txt. There are some paths in there you might need to edit if you want to try it yourself.

@MabezDev
Copy link
Author

MabezDev commented Jan 24, 2021

I've done A little more analysis of the llvm ir.

The issue arises when optimizations are enabled.

# works
llc -filetype=obj core-e40c46572e76fe97.core.7bmkbcle-cgu.0.rcgu.ll -O0

# fails
llc -filetype=obj core-e40c46572e76fe97.core.7bmkbcle-cgu.0.rcgu.ll -O1

Fortunately, that last command tells us some more info, namely that the offending function is @_ZN4core3num6bignum5tests6Big8x310mul_digits17hbefc9cd21174a3deE:

LLVM ERROR: Not supported instr: <MCInst 237 <MCOperand Reg:42>>
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc -filetype=obj core-e40c46572e76fe97.core.7bmkbcle-cgu.0.rcgu.ll -O1 
1.      Running pass 'Function Pass Manager' on module 'core-e40c46572e76fe97.core.7bmkbcle-cgu.0.rcgu.ll'.
2.      Running pass 'Xtensa Assembly Printer' on function '@_ZN4core3num6bignum5tests6Big8x310mul_digits17hbefc9cd21174a3deE'
 #0 0x0000556c3886ff3a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x2243f3a)
 #1 0x0000556c3886de04 llvm::sys::RunSignalHandlers() (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x2241e04)
 #2 0x0000556c3886df48 SignalHandler(int) (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x2241f48)
 #3 0x00007fc863e3cc10 __restore_rt (/lib64/libpthread.so.0+0x12c10)
 #4 0x00007fc8638a4de1 raise (/lib64/libc.so.6+0x38de1)
 #5 0x00007fc86388e536 abort (/lib64/libc.so.6+0x22536)
 #6 0x0000556c387e9756 llvm::report_fatal_error(llvm::Twine const&, bool) (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x21bd756)
 #7 0x0000556c387e98ae (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x21bd8ae)
 #8 0x0000556c37963105 (anonymous namespace)::XtensaMCCodeEmitter::encodeInstruction(llvm::MCInst const&, llvm::raw_ostream&, llvm::SmallVectorImpl<llvm::MCFixup>&, llvm::MCSubtargetInfo const&) const (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x1337105)
 #9 0x0000556c381efd65 llvm::MCELFStreamer::emitInstToData(llvm::MCInst const&, llvm::MCSubtargetInfo const&) (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x1bc3d65)
#10 0x0000556c382050da llvm::MCObjectStreamer::emitInstructionImpl(llvm::MCInst const&, llvm::MCSubtargetInfo const&) (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x1bd90da)
#11 0x0000556c382052b3 llvm::MCObjectStreamer::emitInstruction(llvm::MCInst const&, llvm::MCSubtargetInfo const&) (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x1bd92b3)
#12 0x0000556c377afce5 llvm::XtensaAsmPrinter::emitInstruction(llvm::MachineInstr const*) (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x1183ce5)
#13 0x0000556c37b77871 llvm::AsmPrinter::emitFunctionBody() (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x154b871)
#14 0x0000556c37413795 llvm::AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0xde7795)
#15 0x0000556c37d76e14 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x174ae14)
#16 0x0000556c381288c0 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x1afc8c0)
#17 0x0000556c38129e91 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x1afde91)
#18 0x0000556c38127b08 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x1afbb08)
#19 0x0000556c36c0ab8b compileModule(char**, llvm::LLVMContext&) (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x5deb8b)
#20 0x0000556c36b7ff6e main (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x553f6e)
#21 0x00007fc86388fe6b __libc_start_main (/lib64/libc.so.6+0x23e6b)
#22 0x0000556c36c0434a _start (/home/mabez/development/rust/xtensa/rust-xtensa-dev/build/x86_64-unknown-linux-gnu/llvm/bin/llc+0x5d834a)
[1]    30229 abort       -filetype=obj core-e40c46572e76fe97.core.7bmkbcle-cgu.0.rcgu.ll -O1

Here's the ASM for the offending function, I didn't immediately spot anything out of place:

# -- Begin function _ZN4core3num6bignum5tests6Big8x310mul_digits17hbefc9cd21174a3deE
	.literal .LCPI292_0, .Lalloc23096
	.literal .LCPI292_1, _ZN4core9panicking18panic_bounds_check17h5d2bbbfe824db14cE
	.literal .LCPI292_2, 65280
	.literal .LCPI292_3, _ZN4core5slice5index24slice_end_index_len_fail17h7f5b2f0bae923e3cE
	.global	_ZN4core3num6bignum5tests6Big8x310mul_digits17hbefc9cd21174a3deE
	.p2align	2
	.type	_ZN4core3num6bignum5tests6Big8x310mul_digits17hbefc9cd21174a3deE,@function
_ZN4core3num6bignum5tests6Big8x310mul_digits17hbefc9cd21174a3deE: # @_ZN4core3num6bignum5tests6Big8x310mul_digits17hbefc9cd21174a3deE
# %bb.0:                                # %start
	entry	a1, 64
	mov.n	a15, a3
	movi.n	a12, 0
	s8i	a12, a1, 30
	s16i	a12, a1, 28
	l32i.n	a10, a2, 0
	bltui	a10, 4, .LBB292_1
	j	.LBB292_47
.LBB292_1:                              # %_ZN4core3num6bignum5tests6Big8x36digits17ha50374386d43ca1eE.exit
	addi.n	a11, a2, 4
	bltu	a10, a4, .LBB292_2
	j	.LBB292_19
.LBB292_2:                              # %bb3
	add.n	a8, a15, a4
	s32i.n	a8, a1, 24
	add.n	a9, a10, a2
	addi.n	a10, a9, 5
	addi.n	a8, a4, 1
	s32i.n	a8, a1, 0
	movi.n	a3, 0
	sub	a12, a10, a11
	mov.n	a14, a3
	mov.n	a7, a3
.LBB292_3:                              # %bb4.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB292_11 Depth 2
	mov.n	a6, a7
	addi.n	a9, a12, -1
	beqz	a9, .LBB292_44
# %bb.4:                                # %"_ZN99_$LT$core..iter..adapters..Enumerate$LT$I$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h2f37eb4952fb7497E.exit31.i"
                                        #   in Loop: Header=BB292_3 Depth=1
	l8ui	a5, a11, 0
	addi.n	a7, a6, 1
	addi.n	a11, a11, 1
	beqz	a5, .LBB292_3
# %bb.5:                                # %"_ZN99_$LT$core..iter..adapters..Enumerate$LT$I$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h2f37eb4952fb7497E.exit.lr.ph.i"
                                        #   in Loop: Header=BB292_3 Depth=1
	s32i.n	a10, a1, 8
	movi.n	a10, 3
	sub	a9, a10, a6
	s32i.n	a4, a1, 12
	s32i.n	a12, a1, 4
	bltu	a10, a9, .LBB292_7
# %bb.6:                                # %"_ZN99_$LT$core..iter..adapters..Enumerate$LT$I$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h2f37eb4952fb7497E.exit.lr.ph.i"
                                        #   in Loop: Header=BB292_3 Depth=1
	mov.n	a10, a3
	j	.LBB292_8
.LBB292_7:                              #   in Loop: Header=BB292_3 Depth=1
	movi.n	a10, 1
.LBB292_8:                              # %"_ZN99_$LT$core..iter..adapters..Enumerate$LT$I$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h2f37eb4952fb7497E.exit.lr.ph.i"
                                        #   in Loop: Header=BB292_3 Depth=1
	s32i.n	a14, a1, 16
	s32i.n	a2, a1, 20
	mov.n	a12, a3
	bne	a10, a3, .LBB292_10
# %bb.9:                                # %"_ZN99_$LT$core..iter..adapters..Enumerate$LT$I$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h2f37eb4952fb7497E.exit.lr.ph.i"
                                        #   in Loop: Header=BB292_3 Depth=1
	mov.n	a12, a9
.LBB292_10:                             # %"_ZN99_$LT$core..iter..adapters..Enumerate$LT$I$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h2f37eb4952fb7497E.exit.lr.ph.i"
                                        #   in Loop: Header=BB292_3 Depth=1
	addi.n	a13, a12, 1
	mov.n	a14, a3
	mov.n	a2, a3
	mov.n	a9, a3
	mov.n	a3, a15
.LBB292_11:                             # %"_ZN99_$LT$core..iter..adapters..Enumerate$LT$I$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h2f37eb4952fb7497E.exit.i"
                                        #   Parent Loop BB292_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	add.n	a10, a9, a6
	addi.n	a13, a13, -1
	beqz	a13, .LBB292_45
# %bb.12:                               # %bb19.i
                                        #   in Loop: Header=BB292_11 Depth=2
	addi.n	a4, a3, 1
	movi	a12, 255
	and	a14, a14, a12
	addi	a8, a1, 28
	add.n	a8, a8, a10
	l8ui	a10, a8, 0
	add.n	a10, a10, a14
	l8ui	a14, a3, 0
	mull	a14, a14, a5
	add.n	a10, a10, a14
	s8i	a10, a8, 0
	l32r	a8, .LCPI292_2
	and	a8, a10, a8
	srli	a14, a8, 8
	addi.n	a9, a9, 1
	mov.n	a3, a4
	l32i.n	a8, a1, 24
	bne	a4, a8, .LBB292_11
# %bb.13:                               # %bb14.bb16_crit_edge.i
                                        #   in Loop: Header=BB292_3 Depth=1
	and	a10, a14, a12
	l32i.n	a4, a1, 12
	mov.n	a9, a4
	mov.n	a3, a2
	l32i.n	a12, a1, 4
	beqz	a10, .LBB292_16
# %bb.14:                               # %bb23.i
                                        #   in Loop: Header=BB292_3 Depth=1
	add.n	a10, a6, a4
	movi.n	a8, 2
	bgeu	a8, a10, .LBB292_15
	j	.LBB292_45
.LBB292_15:                             # %bb24.i
                                        #   in Loop: Header=BB292_3 Depth=1
	addi	a8, a1, 28
	add.n	a8, a8, a10
	s8i	a14, a8, 0
	l32i.n	a9, a1, 0
.LBB292_16:                             # %bb25.i
                                        #   in Loop: Header=BB292_3 Depth=1
	add.n	a9, a9, a6
	l32i.n	a8, a1, 16
	bltu	a8, a9, .LBB292_18
# %bb.17:                               # %bb25.i
                                        #   in Loop: Header=BB292_3 Depth=1
	mov.n	a9, a8
.LBB292_18:                             # %bb25.i
                                        #   in Loop: Header=BB292_3 Depth=1
	l32i.n	a10, a1, 8
	sub	a8, a10, a11
	mov.n	a14, a9
	l32i.n	a2, a1, 20
	!loopinit a8
.LBB292_19:                             # %bb2
	beqz	a10, .LBB292_37
# %bb.20:
	add.n	a8, a2, a10
	addi.n	a8, a8, 4
	s32i.n	a8, a1, 24
	addi.n	a8, a10, 1
	s32i.n	a8, a1, 8
	add.n	a9, a4, a15
	mov.n	a14, a12
.LBB292_21:                             # %bb4.outer.i27
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB292_22 Depth 2
                                        #     Child Loop BB292_29 Depth 2
	sub	a8, a9, a15
	addi.n	a8, a8, 1
.LBB292_22:                             # %bb4.i31
                                        #   Parent Loop BB292_21 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	mov.n	a7, a12
	addi.n	a8, a8, -1
	beqz	a8, .LBB292_44
# %bb.23:                               # %"_ZN99_$LT$core..iter..adapters..Enumerate$LT$I$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h2f37eb4952fb7497E.exit31.i34"
                                        #   in Loop: Header=BB292_22 Depth=2
	l8ui	a6, a15, 0
	addi.n	a12, a7, 1
	addi.n	a15, a15, 1
	beqz	a6, .LBB292_22
# %bb.24:                               # %"_ZN99_$LT$core..iter..adapters..Enumerate$LT$I$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h2f37eb4952fb7497E.exit.lr.ph.i37"
                                        #   in Loop: Header=BB292_21 Depth=1
	s32i.n	a9, a1, 12
	movi.n	a9, 3
	sub	a8, a9, a7
	movi.n	a5, 0
	s32i.n	a2, a1, 20
	s32i.n	a14, a1, 16
	bltu	a9, a8, .LBB292_26
# %bb.25:                               # %"_ZN99_$LT$core..iter..adapters..Enumerate$LT$I$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h2f37eb4952fb7497E.exit.lr.ph.i37"
                                        #   in Loop: Header=BB292_21 Depth=1
	mov.n	a9, a5
	mov.n	a14, a5
	beq	a9, a5, .LBB292_27
	j	.LBB292_28
.LBB292_26:                             #   in Loop: Header=BB292_21 Depth=1
	movi.n	a9, 1
	mov.n	a14, a5
	bne	a9, a5, .LBB292_28
.LBB292_27:                             # %"_ZN99_$LT$core..iter..adapters..Enumerate$LT$I$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h2f37eb4952fb7497E.exit.lr.ph.i37"
                                        #   in Loop: Header=BB292_21 Depth=1
	mov.n	a14, a8
.LBB292_28:                             # %"_ZN99_$LT$core..iter..adapters..Enumerate$LT$I$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h2f37eb4952fb7497E.exit.lr.ph.i37"
                                        #   in Loop: Header=BB292_21 Depth=1
	addi.n	a4, a14, 1
	mov.n	a9, a5
	mov.n	a2, a11
.LBB292_29:                             # %"_ZN99_$LT$core..iter..adapters..Enumerate$LT$I$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h2f37eb4952fb7497E.exit.i43"
                                        #   Parent Loop BB292_21 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	add.n	a8, a9, a7
	addi.n	a4, a4, -1
	beqz	a4, .LBB292_46
# %bb.30:                               # %bb19.i60
                                        #   in Loop: Header=BB292_29 Depth=2
	addi.n	a3, a2, 1
	movi	a14, 255
	and	a5, a5, a14
	addi	a13, a1, 28
	add.n	a8, a13, a8
	l8ui	a13, a8, 0
	add.n	a13, a13, a5
	l8ui	a5, a2, 0
	mull	a5, a5, a6
	add.n	a13, a13, a5
	s8i	a13, a8, 0
	l32r	a8, .LCPI292_2
	and	a8, a13, a8
	srli	a5, a8, 8
	addi.n	a9, a9, 1
	mov.n	a2, a3
	l32i.n	a8, a1, 24
	bne	a3, a8, .LBB292_29
# %bb.31:                               # %bb14.bb16_crit_edge.i46
                                        #   in Loop: Header=BB292_21 Depth=1
	and	a9, a5, a14
	mov.n	a8, a10
	l32i.n	a2, a1, 20
	l32i.n	a13, a1, 16
	beqz	a9, .LBB292_34
# %bb.32:                               # %bb23.i63
                                        #   in Loop: Header=BB292_21 Depth=1
	add.n	a8, a7, a10
	movi.n	a9, 2
	bltu	a9, a8, .LBB292_46
# %bb.33:                               # %bb24.i64
                                        #   in Loop: Header=BB292_21 Depth=1
	addi	a9, a1, 28
	add.n	a8, a9, a8
	s8i	a5, a8, 0
	l32i.n	a8, a1, 8
.LBB292_34:                             # %bb25.i69
                                        #   in Loop: Header=BB292_21 Depth=1
	add.n	a8, a8, a7
	bltu	a13, a8, .LBB292_36
# %bb.35:                               # %bb25.i69
                                        #   in Loop: Header=BB292_21 Depth=1
	mov.n	a8, a13
.LBB292_36:                             # %bb25.i69
                                        #   in Loop: Header=BB292_21 Depth=1
	mov.n	a14, a8
	l32i.n	a9, a1, 12
	j	.LBB292_21
.LBB292_37:
	add.n	a8, a4, a15
	mov.n	a14, a12
.LBB292_38:                             # %bb4.outer.us.i13
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB292_39 Depth 2
	sub	a9, a8, a15
	addi.n	a10, a9, 1
.LBB292_39:                             # %bb4.us.i23
                                        #   Parent Loop BB292_38 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	mov.n	a9, a12
	addi.n	a10, a10, -1
	beqz	a10, .LBB292_44
# %bb.40:                               # %"_ZN99_$LT$core..iter..adapters..Enumerate$LT$I$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h2f37eb4952fb7497E.exit31.us.i16"
                                        #   in Loop: Header=BB292_39 Depth=2
	addi.n	a12, a9, 1
	addi.n	a11, a15, 1
	l8ui	a13, a15, 0
	mov.n	a15, a11
	beqz	a13, .LBB292_39
# %bb.41:                               # %bb25.us.i19
                                        #   in Loop: Header=BB292_38 Depth=1
	bltu	a14, a9, .LBB292_43
# %bb.42:                               # %bb25.us.i19
                                        #   in Loop: Header=BB292_38 Depth=1
	mov.n	a9, a14
.LBB292_43:                             # %bb25.us.i19
                                        #   in Loop: Header=BB292_38 Depth=1
	mov.n	a15, a11
	mov.n	a14, a9
	j	.LBB292_38
.LBB292_44:                             # %bb8
	l8ui	a8, a1, 30
	s8i	a8, a2, 6
	l8ui	a8, a1, 29
	s8i	a8, a2, 5
	l8ui	a8, a1, 28
	s8i	a8, a2, 4
	s32i.n	a14, a2, 0
	retw.n
.LBB292_45:                             # %panic5.i
	movi.n	a11, 3
	l32r	a12, .LCPI292_0
	l32r	a8, .LCPI292_1
	callx8	a8
.LBB292_46:                             # %panic5.i71
	movi.n	a11, 3
	l32r	a12, .LCPI292_0
	l32r	a9, .LCPI292_1
	mov.n	a10, a8
	callx8	a9
.LBB292_47:                             # %bb5.i.i.i.i
	movi.n	a11, 3
	l32r	a12, .LCPI292_0
	l32r	a8, .LCPI292_3
	callx8	a8
.Lfunc_end292:
	.size	_ZN4core3num6bignum5tests6Big8x310mul_digits17hbefc9cd21174a3deE, .Lfunc_end292-_ZN4core3num6bignum5tests6Big8x310mul_digits17hbefc9cd21174a3deE
                                        # -- End function

Here's the full asm, created by running llc -filetype=asm core-e40c46572e76fe97.core.7bmkbcle-cgu.0.rcgu.ll -O1.

core-e40c46572e76fe97.core.7bmkbcle-cgu.0.rcgu.s.zip

@kelnos
Copy link

kelnos commented Jan 24, 2021

Ah interesting. In my efforts to look into the new work you started, I ended up building a debug version of llvm/rust, and with debug assertions enabled, I get this now:

$ cargo xbuild --example esp32 --features="xtensa-lx-rt/lx6,xtensa-lx/lx6,esp32-hal"
   Compiling core v0.0.0 (/home/brian/src/esp32-rust/rust-xtensa/library/core)
   Compiling compiler_builtins v0.1.36
   Compiling rustc-std-workspace-core v1.99.0 (/home/brian/src/esp32-rust/rust-xtensa/library/rustc-std-workspace-core)
rustc: /home/brian/src/esp32-rust/rust-xtensa/src/llvm-project/llvm/lib/CodeGen/BranchRelaxation.cpp:335: bool {anonymous}::BranchRelaxation::fixupConditionalBranch(llvm::MachineInstr&): Assertion `!Fail && "branches to be relaxed must be analyzable"' failed.
error: could not compile `core`

Caused by:
  process didn't exit successfully: `/home/brian/src/esp32-rust/rust-xtensa/build/x86_64-unknown-linux-gnu/stage2/bin/rustc --crate-name core --edition=2018 /home/brian/src/esp32-rust/rust-xtensa/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=eefe0737f1bad7ee -C extra-filename=-eefe0737f1bad7ee --out-dir /tmp/cargo-xbuildIMe6T8/target/xtensa-esp32-none-elf/release/deps --target xtensa-esp32-none-elf -L dependency=/tmp/cargo-xbuildIMe6T8/target/xtensa-esp32-none-elf/release/deps -L dependency=/tmp/cargo-xbuildIMe6T8/target/release/deps -Cembed-bitcode=yes` (signal: 6, SIGABRT: process abort signal)
warning: build failed, waiting for other jobs to finish...
error: build failed
error: `"/home/brian/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo" "rustc" "-p" "alloc" "--release" "--manifest-path" "/tmp/cargo-xbuildIMe6T8/Cargo.toml" "--target" "xtensa-esp32-none-elf" "--" "-Z" "force-unstable-if-unmarked"` failed with exit code: Some(101)

BranchRelaxation::fixupConditionalBranch() does sound like something related to the optimizer, so that makes sense that you found that it works ok with optimizations turned off.

Interestingly, if I look at that code, the result that triggers the assertion failure is silently ignored when assertions are disabled.

My intention here was to build a debug, unoptimized version of llc so i could reproduce what you were doing, but in gdb so I could step around to find the exact bit causing the problem. But maybe this result is helpful too. Next step, I want to go back with assertions disabled (but still debug/unoptimized build) so I can get back to the same error state as before.

@kelnos
Copy link

kelnos commented Jan 28, 2021

Figured out the offending commit in LLVM on the xtensa_release_11.0.0 branch: 22aa883

I built rust 1.47.0 against the tip of the xtensa_release_11.0.0 branch, and noticed the same LLVM error. Made me realize that the xtensa-target branch of rust-xtensa was not pointing to the tip of that branch, but to a few commits behind it. Building the rust xtensa-update-17-01-2021 branch against LLVM 9ecb19f results in a seemingly-functioning rustc; at least rust-xtensa-quickstart now compiles properly.

@github-actions github-actions bot changed the title Not supported instr: <MCInst 237 <MCOperand Reg:42>> Not supported instr: <MCInst 237 <MCOperand Reg:42>> (LLVM-85) Jan 28, 2021
@stappersg
Copy link

stappersg commented Jan 28, 2021 via email

@kelnos
Copy link

kelnos commented Jan 28, 2021

Please translate that into "issue should remain open (for ....)" or "close issue"

Issue should remain open because the bug exists on the tip of the llvm xtensa_release_11.0.0 branch. Commit 22aa883 introduced this regression.

@KerryRJ
Copy link

KerryRJ commented Jan 28, 2021

I've built a customized rust using 1.50 beta/1.51 nightly and the Espressif xtensa_release_11.0.0, and an updated esp32-hal and it is compiling the Quickstart, for Esp32, with no problems. I am building on Windows 10 using cargo and not Xargo or Xbuild.

@MabezDev
Copy link
Author

Great spot @kelnos! Awesome work, I've rolled the rust fork back to 9ecb19f esp-rs/rust#44 and rebuilt and it works perfectly! Will merge to the xtensa-target branch soon.

I've built a customized rust using 1.50 beta/1.51 nightly and the Espressif xtensa_release_11.0.0, and an updated esp32-hal and it is compiling the Quickstart, for Esp32, with no problems. I am building on Windows 10 using cargo and not Xargo or Xbuild.

Does it still work if you build in release? If you're using cargo via -Z build-std then it will compile core in debug too, where as Xargo etc will always compile core in release mode.

@MabezDev
Copy link
Author

@andreisfr FYI this is the rust code that causes the error: https://github.com/rust-lang/rust/blob/master/library/core/src/num/bignum.rs#L325
Unfortunately its wrapped up in a macro and only fails in this instance.

I will try and produce a minimal C example if I have time over the weekend.

@KerryRJ
Copy link

KerryRJ commented Jan 29, 2021

I was using cargo build --example esp32 --release to get the quickstart building with no core. The error does indeed appear when adding -Z build-std.

@andreisfr
Copy link
Collaborator

@andreisfr FYI this is the rust code that causes the error: https://github.com/rust-lang/rust/blob/master/library/core/src/num/bignum.rs#L325
Unfortunately its wrapped up in a macro and only fails in this instance.

I will try and produce a minimal C example if I have time over the weekend.

Hi @MabezDev, thank you very much for your investigation! It would be very helpful to have an С example which demonstrates the problem to solve it quickly.

Thanks also to all for support!

@aykevl
Copy link

aykevl commented Feb 3, 2021

Here is a small reproducer in IR form:

target datalayout = "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32"
target triple = "xtensa-none-unknown-elf"

define void @crashing() {
entry:
  br i1 undef, label %bb1, label %bb2

bb1:
  %a = phi i32 [ 0, %entry ], [ %b, %bb2 ]
  unreachable

bb2:
  %b = phi i32 [ %c, %bb2 ], [ 1, %entry ]
  %c = add i32 %b, 1
  %cond = icmp eq i32 %b, 0
  br i1 %cond, label %bb1, label %bb2
}

Reproduce using:

llc -filetype=obj reproducer.ll -O1

I don't have a C example, but hopefully this IR will also be enough to fix this bug. Or maybe someone else can try to create a C example based on this IR.

@aykevl
Copy link

aykevl commented Feb 3, 2021

I managed to get this small IR reproducer using bugpoint, opt, and some manual reducing of the function.

  1. bugpoint: I ran bugpoint --llc-safe xtensa-issue43.ll to reduce the file as far as possible. Unfortunately, bugpoint was hanging during the "Attempting to reduce the number of function attributes in the testcase" but luckily it had produced a bugpoint-reduced-function.bc file just before that hang which I could work with. It's a large bitcode file (easily disassembled with llvm-dis) but where only one function still has a body: clearly the offending function. Still, I needed to reduce it further.
  2. As a solution, I ran opt -O2 on the resulting file, in an attempt to remove the function attributes bugpoint was hanging at.
  3. This worked. A further bugpoint --llc-safe on the optimized file resulted in IR that was just 26 lines long - much easier to work with!
  4. With some fine tuning I managed to bring down the file size further, to just 17 lines of IR (7 instructions over 3 basic blocks).

Normally only bugpoint with some manual tuning is necessary, but in this case clearly some creativity was needed to reduce this bug. I hope this helps people interested in reducing test cases for LLVM crashes.

@andreisfr
Copy link
Collaborator

Hi, @aykevl! Thank you very much for example. Did you observed similar llc's output in example?

Assertion failed: (BrOffset <= 0) && "Wrong hardware loop", file llvm-project\llvm\lib\Target\Xtensa\XtensaInstrInfo.cpp, line 321
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.      Program arguments: build\Debug\bin\llc.exe -filetype=obj reproducer.ll -O1
1.      Running pass 'Function Pass Manager' on module 'reproducer.ll'.
2.      Running pass 'Branch relaxation pass' on function 

@aykevl
Copy link

aykevl commented Feb 9, 2021

Yes, this is the crash log I'm getting:

$ llc -filetype=obj reproducer.ll -O1
llc: /home/ayke/src/github.com/tinygo-org/tinygo/llvm-project/llvm/lib/Target/Xtensa/XtensaInstrInfo.cpp:321: virtual bool llvm::XtensaInstrInfo::isBranchOffsetInRange(unsigned int, int64_t) const: Assertion `(BrOffset <= 0) && "Wrong hardware loop"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/ayke/src/github.com/tinygo-org/tinygo/llvm-build/bin/llc -filetype=obj reproducer.ll -O1 
1.	Running pass 'Function Pass Manager' on module 'reproducer.ll'.
2.	Running pass 'Branch relaxation pass' on function '@crashing'
 #0 0x0000000002ea71b4 PrintStackTraceSignalHandler(void*) (/home/ayke/src/github.com/tinygo-org/tinygo/llvm-build/bin/llc+0x2ea71b4)
 #1 0x0000000002ea4d8e llvm::sys::RunSignalHandlers() (/home/ayke/src/github.com/tinygo-org/tinygo/llvm-build/bin/llc+0x2ea4d8e)
 #2 0x0000000002ea74d5 SignalHandler(int) (/home/ayke/src/github.com/tinygo-org/tinygo/llvm-build/bin/llc+0x2ea74d5)
 #3 0x00007f14bca7d730 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12730)
 #4 0x00007f14bc5af7bb raise (/lib/x86_64-linux-gnu/libc.so.6+0x377bb)
 #5 0x00007f14bc59a535 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22535)
 #6 0x00007f14bc59a40f (/lib/x86_64-linux-gnu/libc.so.6+0x2240f)
 #7 0x00007f14bc5a8102 (/lib/x86_64-linux-gnu/libc.so.6+0x30102)
 #8 0x0000000001e1e5a6 llvm::XtensaInstrInfo::isBranchOffsetInRange(unsigned int, long) const (/home/ayke/src/github.com/tinygo-org/tinygo/llvm-build/bin/llc+0x1e1e5a6)
 #9 0x0000000002185025 (anonymous namespace)::BranchRelaxation::isBlockInRange(llvm::MachineInstr const&, llvm::MachineBasicBlock const&) const (/home/ayke/src/github.com/tinygo-org/tinygo/llvm-build/bin/llc+0x2185025)
#10 0x00000000021836d5 (anonymous namespace)::BranchRelaxation::runOnMachineFunction(llvm::MachineFunction&) (/home/ayke/src/github.com/tinygo-org/tinygo/llvm-build/bin/llc+0x21836d5)
#11 0x00000000022e8b9d llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/ayke/src/github.com/tinygo-org/tinygo/llvm-build/bin/llc+0x22e8b9d)
#12 0x00000000026cfce4 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/ayke/src/github.com/tinygo-org/tinygo/llvm-build/bin/llc+0x26cfce4)
#13 0x00000000026d6418 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/ayke/src/github.com/tinygo-org/tinygo/llvm-build/bin/llc+0x26d6418)
#14 0x00000000026d0534 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/ayke/src/github.com/tinygo-org/tinygo/llvm-build/bin/llc+0x26d0534)
#15 0x000000000170a3e9 main (/home/ayke/src/github.com/tinygo-org/tinygo/llvm-build/bin/llc+0x170a3e9)
#16 0x00007f14bc59c09b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409b)
#17 0x0000000001707e8a _start (/home/ayke/src/github.com/tinygo-org/tinygo/llvm-build/bin/llc+0x1707e8a)

@andreisfr
Copy link
Collaborator

Hi @MabezDev , @aykevl ! Thank you very much for help! We fixed this issue in LLVM, please use latest version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants