[llvm] [AsmPrinter] Fix emission in asm of alignment 2^32. (PR #98688)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 16 14:51:48 PDT 2024
https://github.com/efriedma-quic updated https://github.com/llvm/llvm-project/pull/98688
>From 0ce5e3f596b883d506574a0b43e243383a9cd23a Mon Sep 17 00:00:00 2001
From: Eli Friedman <efriedma at quicinc.com>
Date: Fri, 12 Jul 2024 12:41:52 -0700
Subject: [PATCH 1/2] [AsmPrinter] Fix emission in asm of alignment 2^32.
The alignment amount was getting corrupted due to accidental truncation.
---
llvm/lib/MC/MCAsmStreamer.cpp | 12 ++++++------
llvm/test/CodeGen/X86/global-with-max-align.ll | 14 ++++++++++++++
2 files changed, 20 insertions(+), 6 deletions(-)
create mode 100644 llvm/test/CodeGen/X86/global-with-max-align.ll
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
+
+ at g1 = global i32 0, align 4294967296
+ at g2 = global i32 33, align 4294967296
+ at g3 = constant i32 44, align 4294967296
>From e252523da90eb81592d6942faee964fb0a5ff31c Mon Sep 17 00:00:00 2001
From: Eli Friedman <efriedma at quicinc.com>
Date: Tue, 16 Jul 2024 14:51:25 -0700
Subject: [PATCH 2/2] fixup! address review comments.
---
llvm/test/CodeGen/X86/global-with-max-align.ll | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/test/CodeGen/X86/global-with-max-align.ll b/llvm/test/CodeGen/X86/global-with-max-align.ll
index 76617abaae5f6..5cd360b55540d 100644
--- a/llvm/test/CodeGen/X86/global-with-max-align.ll
+++ b/llvm/test/CodeGen/X86/global-with-max-align.ll
@@ -1,5 +1,7 @@
; RUN: llc -mtriple=x86_64 < %s | FileCheck %s
+; Make sure alignment of 2^32 isn't truncated to zero.
+
; CHECK: .globl g1
; CHECK-NEXT: .p2align 32, 0x0
; CHECK: .globl g2
@@ -7,8 +9,6 @@
; 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
More information about the llvm-commits
mailing list