[hexagon] "Bad machine code: Virtual register defs don't dominate all uses." when bootstrapping
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
@llvm/issue-subscribers-backend-hexagon
Author: Brian Cain (androm3da)
./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
/cherry-pick f3a60cf8dd602958f706c11db66e401257364be7
/pull-request llvm/llvm-project#164354
@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.
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.