This is an archive of the discontinued LLVM Phabricator instance.

[MachineInst] Bump NumOperands back up to 24bits
ClosedPublic

Authored by jroelofs on Jun 26 2023, 10:42 AM.

Details

Summary

In https://reviews.llvm.org/D149445, it was lowered from 32 to 16bits, which broke an internal project of ours. The relevant code being compiled is a fairly large nested switch that results in a PHI node with 65k+ operands, which can't easily be turned into a table for perf reasons.

This change unifies NumOperands, Flags, and AsmPrinterFlags into a packed 7-byte struct, which CapOperands can follow as the 8th byte, rounding it up to a nice alignment before the Info field.

rdar://111217742&109362033

Diff Detail

Event Timeline

jroelofs created this revision.Jun 26 2023, 10:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 26 2023, 10:42 AM
jroelofs requested review of this revision.Jun 26 2023, 10:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 26 2023, 10:42 AM
jroelofs edited the summary of this revision. (Show Details)Jun 26 2023, 10:44 AM

Looks fine

llvm/lib/CodeGen/MachineInstr.cpp
196–197

formatting

jroelofs updated this revision to Diff 534654.Jun 26 2023, 11:00 AM

git-clang-format'd the patch

jroelofs updated this revision to Diff 534656.Jun 26 2023, 11:03 AM

clarify assert strings

nikic added inline comments.Jun 26 2023, 1:12 PM
llvm/include/llvm/CodeGen/MachineInstr.h
137

Why do we need the packed struct wrapper here? Doesn't defining these bitfields directly in the class work?

jroelofs added inline comments.Jun 26 2023, 1:33 PM
llvm/include/llvm/CodeGen/MachineInstr.h
137

The two 24-bit fields need to be part of a packed struct, otherwise we get some padding [1]. We can either do that around the whole struct, or just these 56 bits. I don't have a strong opinion either way.

1: https://clang.godbolt.org/z/4Kxs4fKc7

xbolva00 added a comment.EditedJun 26 2023, 1:44 PM

whole struct would be probably better, less churn. Plus, can we static_assert that size is <= XY?

nikic added inline comments.Jun 26 2023, 1:45 PM
llvm/include/llvm/CodeGen/MachineInstr.h
137

Can you avoid the need for that by reordering the fields to be 24 8 24 8? E.g. Flags, AsmPrinterFlags, NumOperands, CapOperands.

jroelofs added inline comments.Jun 26 2023, 1:49 PM
llvm/include/llvm/CodeGen/MachineInstr.h
137

Good eye! Yeah, that works: https://clang.godbolt.org/z/q1onMv94e

jroelofs updated this revision to Diff 534767.Jun 26 2023, 3:34 PM
craig.topper added inline comments.Jun 26 2023, 4:16 PM
llvm/include/llvm/CodeGen/MachineInstr.h
137

If I remember right, doesn't MSVC pack bit fields differently than clang/gcc?

nikic added inline comments.Jun 27 2023, 12:36 AM
llvm/include/llvm/CodeGen/MachineInstr.h
137

Yes, for this to work on MSVC we would need all of these fields to have the same type (with different widths). However, MSVC does not produce correct layout even with packed structs. It ends up with a 34 byte struct (rather than 32 or 40), so I can only assume we'll get a terrible unaligned mess if we do that.

So I think we should just accept the size increase on MSVC.

385

These can use isUInt<LLVM_MI_FLAGS_BITS>(Flag) etc. (Though maybe not worth including the header if it's not already used.)

jroelofs updated this revision to Diff 535141.Jun 27 2023, 2:35 PM
jroelofs marked 2 inline comments as done.

llvm:isUInt<>

nikic accepted this revision.Jun 28 2023, 12:29 AM

LGTM

This revision is now accepted and ready to land.Jun 28 2023, 12:29 AM
jroelofs added inline comments.Jun 28 2023, 10:08 AM
llvm/include/llvm/CodeGen/MachineInstr.h
137

Does MSVC have an analog to -fdump-record-layouts?

385

Thanks for the pointer. ArrayRecycler.h pulls it in, so it's low overhead to use it here.

This revision was landed with ongoing or failed builds.Jun 28 2023, 10:32 AM
This revision was automatically updated to reflect the committed changes.