This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Add frozen for the condition value of SelectInst
ClosedPublic

Authored by Allen on Apr 27 2023, 5:46 AM.

Details

Summary

If the condition value of SelectInst may be a poison or undef value,
infer constant range at SelectInst use is incorrect, similar to D143883.

Fixes https://github.com/llvm/llvm-project/issues/62401

Diff Detail

Event Timeline

Allen created this revision.Apr 27 2023, 5:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2023, 5:46 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
Allen requested review of this revision.Apr 27 2023, 5:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2023, 5:46 AM
nikic requested changes to this revision.Apr 27 2023, 6:00 AM

It would be better to freeze the operand instead.

This revision now requires changes to proceed.Apr 27 2023, 6:00 AM
Allen updated this revision to Diff 517537.Apr 27 2023, 6:16 AM
Allen retitled this revision from [InstCombine] Cond value of selectinst should be well-defined to [InstCombine] Add frozen for the condition value of SelectInst.
Allen edited the summary of this revision. (Show Details)

address comment

nikic accepted this revision.Apr 27 2023, 6:29 AM

LGTM

This revision is now accepted and ready to land.Apr 27 2023, 6:29 AM
This revision was landed with ongoing or failed builds.Apr 27 2023, 6:36 AM
This revision was automatically updated to reflect the committed changes.

(For future reference, the freeze isn't necessary if the operand is poison; it's only necessary if the operand is undef.)

Allen added a comment.Apr 27 2023, 6:14 PM

(For future reference, the freeze isn't necessary if the operand is poison; it's only necessary if the operand is undef.)

hi, @efriedma, Thanks for your information.

do you mean we'd better check the attribute **noundef ** before adding the **freeze** ? such as  https://alive2.llvm.org/ce/z/2pIqvX, this case isn't necessary to add freeze  ?

I don't think there's anything to do here at the moment. "noundef" refers to both undef and poison. (Later optimizations will remove the "freeze" if it isn't necessary.)