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

Fatal error: error in backend: Broken module found, compilation aborted! while processing profiled LLVM IR with Oz optimization

Open iamaayushrivastava opened this issue 1 year ago • 6 comments

Hi, I'm encountering a backend compilation error while using the LLVM inliner in release mode on a .ll file that contains call graph profile metadata.

Setup

LLVM/Clang Version: clang version 17.0.0 Commit: f4dbf5babe7a0089322ed64d1623fb31f7d51898 Target: x86_64-unknown-linux-gnu Optimization level: -Oz

Input: LLVM IR file containing the following metadata

!33 = !{i32 5, !"CG Profile", !34}

Error message

module flag identifiers must be unique (or of 'require' type) !"CG Profile" fatal error: error in backend: Broken module found, compilation aborted!

Issue

When trying to process the IR with the inliner, I get a fatal backend error stating that the module flag identifiers must be unique. The error seems to be related to the !"CG Profile" flag.

Please find the attached ll file for your reference.

505-implicit.txt

iamaayushrivastava avatar Apr 10 '25 13:04 iamaayushrivastava

Could you please try 20 or main branch? https://godbolt.org should be helpful.

EugeneZelenko avatar Apr 10 '25 14:04 EugeneZelenko

Could you please try 20 or main branch? https://godbolt.org should be helpful.

Actually, I want to process the profiled .ll files with clang version 17.0.0. Is there any fix for this version?

iamaayushrivastava avatar Apr 10 '25 14:04 iamaayushrivastava

Only most recent release in maintained.

EugeneZelenko avatar Apr 10 '25 14:04 EugeneZelenko

Do you mean that this issue persists with clang version 17.0.0?

iamaayushrivastava avatar Apr 10 '25 17:04 iamaayushrivastava

If problem was fixed in later version you could try to find fix and backport it to 17.x branch yourself.

EugeneZelenko avatar Apr 10 '25 17:04 EugeneZelenko

I have observed that the current LLVM Inliner does not process the CG Profile metadata correctly. When the CG metadata entry !33 = !{i32 5, !"CG Profile", !34} is included in !llvm.module.flags, the LLVM Inliner fails to process the IR. Removing this entry from !llvm.module.flags = !{!0, !1, !2, !3, !4, !33} allows it to proceed as expected.

This suggests that the Inliner may require modifications to support CG Profile metadata. I would appreciate any suggestions or directions you may have on addressing this.

iamaayushrivastava avatar Apr 10 '25 18:04 iamaayushrivastava