This is an archive of the discontinued LLVM Phabricator instance.

MachineConstantPool::getConstantPoolIndex - don't reuse mismatched constants contained undef/poison (Issue #63108)
ClosedPublic

Authored by RKSimon on Jun 7 2023, 3:36 AM.

Details

Summary

This patch fixes an issue where we were reusing constant pool entries that contained undef elements, despite the additional uses of the 'equivalent constant' requiring some/all of the elements to be zero.

The CanShareConstantPoolEntry helper function uses ConstantFoldCastOperand to bitcasts the type mismatching constants to integer representations to allow comparison, but unfortunately this treats undef elements as zero (which they will be written out as in the final asm). This caused an issue where the original constant pool entry contained undef elements, which shared with a later constant that required the elements to be zero. This then caused a later analysis pass to incorrectly discard these undef elements.

Ideally we need a more thorough analysis / merging of the constant pool entries so the elements are forced to real zero elements, but for now we just prevent reuse of the constant pool entry entirely if the constants don't have matching undef/poison elements.

Fixes #63108

Diff Detail

Event Timeline

RKSimon created this revision.Jun 7 2023, 3:36 AM
RKSimon requested review of this revision.Jun 7 2023, 3:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2023, 3:36 AM
goldstein.w.n added a subscriber: goldstein.w.n.EditedJun 12 2023, 10:20 AM

re: "... but for now we just prevent reuse of the constant pool entry entirely."
->
".... but for now we just prevent reuse of the constant pool entry entirely *if there are any undef or poison elements*".

Otherwise, I don't think I really have the expertise to approve this, but FWIW LGTM.

RKSimon edited the summary of this revision. (Show Details)Jun 12 2023, 11:35 AM
nikic accepted this revision.Jun 12 2023, 11:53 AM

LGTM

This revision is now accepted and ready to land.Jun 12 2023, 11:53 AM

Maybe worth intentionally noting that it's fine if B contains undef because if the check succeeds, we completely discard the constant B (so its contents don't matter).

It's a little weird that it's asymmetric like that, but I don't imagine it causes any immediate issue. (Merging constant pools isn't really that important at this level anyway because the linker also merges constant pools.)