Skip to content

Regression: huge .rodata section generated because of constant vector of bool. #55522

New issue

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

By clicking “No 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? No Sign in to your account

Closed
gwenzek opened this issue May 17, 2022 · 6 comments
Closed

Comments

@gwenzek
Copy link

gwenzek commented May 17, 2022

Given the simple .ll file @0 = internal constant <4 x i1> <i1 true, i1 false, i1 true, i1 false>,
LLVM 14 will generate an object file with 4Gb of rodata

$ rm reduced.o ; cat reduced.ll && ~/Downloads/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/llc --filetype=obj reduced.ll && size -A reduced.o
@0 = internal constant <4 x i1> <i1 true, i1 false, i1 true, i1 false>
reduced.o  :
section                 size   addr
.text                      0      0
.rodata           4294967297      0
.note.GNU-stack            0      0
Total             4294967297

If I try with vector of i8, I correctly obtain 4 bytes of rodata.

$ rm reduced.o ; cat reduced.ll && ~/Downloads/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/llc --filetype=obj reduced.ll && size -A reduced.o
@0 = internal constant <4 x i8> <i8 1, i8 0, i8 1, i8 0>
reduced.o  :
section           size   addr
.text                0      0
.rodata              4      0
.note.GNU-stack      0      0
Total                4

Vectors of i2, and i4 also generate the same issue.

This seems to be a regression from LLVM 13 where this was working fine (I believe the warning is just because my .ll is too dry).

$ rm reduced.o ; cat reduced.ll && ~/Downloads/clang+llvm-13.0.1-x86_64-linux-gnu-ubuntu-18.04/bin/llc --filetype=obj reduced.ll && size -A reduced.o
@0 = internal constant <4 x i1> <i1 true, i1 false, i1 true, i1 false>
~Downloads/clang+llvm-13.0.1-x86_64-linux-gnu-ubuntu-18.04/bin/llc: /lib64/libtinfo.so.5: no version information available (required by ~/Downloads/clang+llvm-13.0.1-x86_64-linux-gnu-ubuntu-18.04/bin/llc)
reduced.o  :
section           size   addr
.text                0      0
.rodata              4      0
.note.GNU-stack      0      0
Total                4

I've tried searching for similar issue but without success.

@gwenzek
Copy link
Author

gwenzek commented May 30, 2022

AFAICT this is still an issue on LLVM 14.04

@BertalanD
Copy link
Member

BertalanD commented Jul 3, 2022

With the following assertion added, we can see what the issue is:

diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 4a31bf85446b..7326d161deb6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2981,6 +2981,7 @@ static void emitGlobalConstantVector(const DataLayout &DL,
   unsigned Size = DL.getTypeAllocSize(CV->getType());
   unsigned EmittedSize = DL.getTypeAllocSize(CV->getType()->getElementType()) *
                          CV->getType()->getNumElements();
+  assert(EmittedSize <= Size && "Size cannot be less than EmittedSize!");
   if (unsigned Padding = Size - EmittedSize)
     AP.OutStreamer->emitZeros(Padding);
 }

The debugger shows that Size is 1 and EmittedSize is 4, so we end up wanting to add -3 bytes of padding, which becomes the huge value when it's assigned to unsigned Padding.

I've bisected it to bdd55b2 ("Fix the default alignment of i1 vectors.", @efriedma-quic)

It's still broken on trunk.

@efriedma-quic
Copy link
Collaborator

The generated code isn't really correct even on older versions of LLVM. I'll take a look.

@efriedma-quic
Copy link
Collaborator

Posted https://reviews.llvm.org/D129164

@joebonrichie
Copy link

Can this be backported for 14.0.7?

@EugeneZelenko
Copy link
Contributor

@joebonrichie: 14.0.6 was last release of 14.

@tstellar tstellar moved this to Needs Triage in LLVM Release Status Aug 2, 2022
@tstellar tstellar moved this from Needs Triage to Needs Review in LLVM Release Status Aug 2, 2022
@nikic nikic moved this from Needs Review to Done in LLVM Release Status Aug 2, 2022
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
Vectors are defined to be tightly packed, regardless of the element
type.  The AsmPrinter didn't realize this, and was allocating extra
padding.

Fixes llvm/llvm-project#49286
Fixes llvm/llvm-project#53246
Fixes llvm/llvm-project#55522

Differential Revision: https://reviews.llvm.org/D129164
jayschwa added a commit to jayschwa/zig that referenced this issue Sep 26, 2023
Vexu pushed a commit to ziglang/zig that referenced this issue Sep 26, 2023
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

6 participants