Skip to content

[MC] Fix emission in asm of alignment 2^32. #98688

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

Merged
merged 2 commits into from
Jul 17, 2024

Conversation

efriedma-quic
Copy link
Collaborator

The alignment amount was getting corrupted due to accidental truncation.

The alignment amount was getting corrupted due to accidental truncation.
@efriedma-quic efriedma-quic requested a review from MaskRay July 12, 2024 19:48
@llvmbot llvmbot added backend:X86 mc Machine (object) code labels Jul 12, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 12, 2024

@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-mc

Author: Eli Friedman (efriedma-quic)

Changes

The alignment amount was getting corrupted due to accidental truncation.


Full diff: https://github.com/llvm/llvm-project/pull/98688.diff

2 Files Affected:

  • (modified) llvm/lib/MC/MCAsmStreamer.cpp (+6-6)
  • (added) llvm/test/CodeGen/X86/global-with-max-align.ll (+14)
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 45c32f13e759b..24209e456b5e2 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -254,7 +254,7 @@ class MCAsmStreamer final : public MCStreamer {
   void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
                 SMLoc Loc = SMLoc()) override;
 
-  void emitAlignmentDirective(unsigned ByteAlignment,
+  void emitAlignmentDirective(uint64_t ByteAlignment,
                               std::optional<int64_t> Value, unsigned ValueSize,
                               unsigned MaxBytesToEmit);
 
@@ -1478,23 +1478,23 @@ void MCAsmStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
   EmitEOL();
 }
 
-void MCAsmStreamer::emitAlignmentDirective(unsigned ByteAlignment,
+void MCAsmStreamer::emitAlignmentDirective(uint64_t ByteAlignment,
                                            std::optional<int64_t> Value,
                                            unsigned ValueSize,
                                            unsigned MaxBytesToEmit) {
   if (MAI->useDotAlignForAlignment()) {
-    if (!isPowerOf2_32(ByteAlignment))
+    if (!isPowerOf2_64(ByteAlignment))
       report_fatal_error("Only power-of-two alignments are supported "
                          "with .align.");
     OS << "\t.align\t";
-    OS << Log2_32(ByteAlignment);
+    OS << Log2_64(ByteAlignment);
     EmitEOL();
     return;
   }
 
   // Some assemblers don't support non-power of two alignments, so we always
   // emit alignments as a power of two if possible.
-  if (isPowerOf2_32(ByteAlignment)) {
+  if (isPowerOf2_64(ByteAlignment)) {
     switch (ValueSize) {
     default:
       llvm_unreachable("Invalid size for machine code value!");
@@ -1511,7 +1511,7 @@ void MCAsmStreamer::emitAlignmentDirective(unsigned ByteAlignment,
       llvm_unreachable("Unsupported alignment size!");
     }
 
-    OS << Log2_32(ByteAlignment);
+    OS << Log2_64(ByteAlignment);
 
     if (Value.has_value() || MaxBytesToEmit) {
       if (Value.has_value()) {
diff --git a/llvm/test/CodeGen/X86/global-with-max-align.ll b/llvm/test/CodeGen/X86/global-with-max-align.ll
new file mode 100644
index 0000000000000..76617abaae5f6
--- /dev/null
+++ b/llvm/test/CodeGen/X86/global-with-max-align.ll
@@ -0,0 +1,14 @@
+; RUN: llc -mtriple=x86_64 < %s | FileCheck %s
+
+; CHECK: .globl  g1
+; CHECK-NEXT: .p2align 32, 0x0
+; CHECK: .globl  g2
+; CHECK-NEXT: .p2align 32, 0x0
+; CHECK: .globl  g3
+; CHECK-NEXT: .p2align 32, 0x0
+
+; OBJ: ZZZ
+
+@g1 = global i32 0, align 4294967296
+@g2 = global i32 33, align 4294967296
+@g3 = constant i32 44, align 4294967296

; CHECK: .globl g3
; CHECK-NEXT: .p2align 32, 0x0

; OBJ: ZZZ
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused check prefix?

@@ -0,0 +1,14 @@
; RUN: llc -mtriple=x86_64 < %s | FileCheck %s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a file-level comment what the test is about.

@efriedma-quic efriedma-quic merged commit 2d42f84 into llvm:main Jul 17, 2024
5 of 6 checks passed
@efriedma-quic efriedma-quic changed the title [AsmPrinter] Fix emission in asm of alignment 2^32. [MC] Fix emission in asm of alignment 2^32. Jul 17, 2024
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
The alignment amount was getting corrupted due to accidental truncation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants