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

[hexagon] "Bad machine code: Virtual register defs don't dominate all uses." when bootstrapping

Open androm3da opened this issue 1 year ago • 5 comments

When building LLVM for hexagon, we see the failure shown below. The compiler hits this error when building AArch64MCCodeEmitter.cpp.

./bin/llc --mtriple=hexagon ./reduced.ll

remark: Misaligned constant address: 0x0000003c has alignment 4, but the memory access requires 8. The instruction has been replaced with a trap.

# After Instruction Selection
# Machine code for function _ZNK12_GLOBAL__N_120AArch64MCCodeEmitter21getBinaryCodeForInstrERKN4llvm6MCInstERNS1_15SmallVectorImplINS1_7MCFixupEEERKNS1_15MCSubtargetInfoE: IsSSA, TracksLiveness
Frame Objects:
...
*** Bad machine code: Virtual register defs don't dominate all uses. ***
- function:    _ZNK12_GLOBAL__N_120AArch64MCCodeEmitter21getBinaryCodeForInstrERKN4llvm6MCInstERNS1_15SmallVectorImplINS1_7MCFi
xupEEERKNS1_15MCSubtargetInfoE
- v. register: %3611
...

Reduced test case, output from llc:

Original issue reported by @alexrp:

One other crash: https://files.alexrp.com/AArch64MCCodeEmitter-02318c.cpp https://files.alexrp.com/AArch64MCCodeEmitter-02318c.sh

androm3da avatar Oct 16 '25 13:10 androm3da

@llvm/issue-subscribers-backend-hexagon

Author: Brian Cain (androm3da)

When building LLVM for hexagon, we see the failure shown below. The compiler hits this error when building `AArch64MCCodeEmitter.cpp`.
./bin/llc --mtriple=hexagon ./reduced.ll

remark: Misaligned constant address: 0x0000003c has alignment 4, but the memory access requires 8. The instruction has been replaced with a trap.

# After Instruction Selection
# Machine code for function _ZNK12_GLOBAL__N_120AArch64MCCodeEmitter21getBinaryCodeForInstrERKN4llvm6MCInstERNS1_15SmallVectorImplINS1_7MCFixupEEERKNS1_15MCSubtargetInfoE: IsSSA, TracksLiveness
Frame Objects:
...
*** Bad machine code: Virtual register defs don't dominate all uses. ***
- function:    _ZNK12_GLOBAL__N_120AArch64MCCodeEmitter21getBinaryCodeForInstrERKN4llvm6MCInstERNS1_15SmallVectorImplINS1_7MCFi
xupEEERKNS1_15MCSubtargetInfoE
- v. register: %3611
...

Reduced test case, output from llc:

Original issue reported by @alexrp:

>One other crash: > https://files.alexrp.com/AArch64MCCodeEmitter-02318c.cpp > https://files.alexrp.com/AArch64MCCodeEmitter-02318c.sh

llvmbot avatar Oct 16 '25 13:10 llvmbot

/cherry-pick f3a60cf8dd602958f706c11db66e401257364be7

androm3da avatar Oct 21 '25 01:10 androm3da

/pull-request llvm/llvm-project#164354

llvmbot avatar Oct 21 '25 02:10 llvmbot

@androm3da "remark: Misaligned constant address..." is due to %663 = load ptr, ptr inttoptr (i32 60 to ptr), align 8 in reduced.ll which does not look valid, and I don't know where it comes from. I could not reproduce it on the cpp file. The concern here is compiler may remove a chunk of code due to perceived UB but this is ~expected. I will leave it up to you to create a new issue if it shows up.

quic-akaryaki avatar Oct 22 '25 21:10 quic-akaryaki

I couldn't find this pattern in the original (unreduced) .ll file. Here's aarch64mccodeem.ll.xz.txt the file, compressed (and renamed as if it were a text file to avoid the github file extension filter).

$ grep -c 'load ptr, ptr inttoptr' aarch64mccodeem.ll
0

I will leave it up to you to create a new issue if it shows up.

It's likely an artifact of the reduction process, I don't think we'll need another issue.

androm3da avatar Oct 22 '25 22:10 androm3da