Skip to content

GH-55763: [C++] util: making SafeCopy call std::bit_cast and avoid gcc's LAUNCH - #55764

Open
mapleFU wants to merge 1 commit into
apache:mainfrom
mapleFU:safe-copy-using-cxx20
Open

mapleFU wants to merge 1 commit into
apache:mainfrom
mapleFU:safe-copy-using-cxx20

Conversation

@mapleFU

@mapleFU mapleFU commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Rationale for this change

See #55763

What changes are included in this PR?

Change SafeCopy to call std::bit_cast.

Are these changes tested?

Covered by existing.

Are there any user-facing changes?

no

Was AI used for this PR?

PR code and description written by:

  • Human

Reviewed before submission by:

  • Human
  • AI

Copilot AI balanced review requested due to automatic review settings November 24, 2026 15:14
@mapleFU

mapleFU commented Nov 24, 2026 •

Copy link
Copy Markdown
Member Author

@pitrou I found gcc and x86 decoding ALP can be optimized with this 😅, would you mind take a look? ( clang will not be affected )

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The header lacks a direct <bit> include for std::bit_cast, causing compilation failures when transitive includes do not provide its declaration, even if SafeCopy is never instantiated.

1 open issue
What changed in this PR

This PR modernizes arrow::util::SafeCopy to use C++20 std::bit_cast, addressing the GCC loop-vectorization barrier described in #55763.

Changes:

  • Replaces aligned storage, memory copying, and cleanup with a direct std::bit_cast call.
  • Preserves the existing type constraints and return type.
File Description
cpp/​src/​arrow/​util/​ubsan.h Simplifies SafeCopy to avoid the aligned-storage laundering path.

Review effort: Balanced

Comment thread cpp/src/arrow/util/ubsan.h Resolved
@mapleFU
mapleFU force-pushed the safe-copy-using-cxx20 branch from 5bd5e64 to ba16e7c Compare November 24, 2026 16:22
Copilot AI balanced review requested due to automatic review settings November 24, 2026 16:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the SafeCopy simplification.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@Sumdiboii

Copy link
Copy Markdown
Contributor

Hey @mapleFU , nice find! I see the old version went through std::launder, but I'm not sure why that blocks gcc's optimization and not clang's. Would you mind explaining a bit? I'm trying to learn how this works.

@mapleFU

mapleFU commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

You can gothrough the issue, in gcc, the code below prevents from auto vectorization.

missed: statement clobbers memory: _21 = .LAUNDER (&raw_data.data_);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants