Page MenuHomePhabricator

[InstSimplify] Fold out-of-bounds shift to poison

Authored by nikic on Jan 3 2021, 12:13 PM.



Make InstSimplify return poison rather than undef for out-of-bounds shifts, as specified by LandRef:

If op2 is (statically or dynamically) equal to or larger than the number of bits in op1, this instruction returns a poison value.

Diff Detail

Event Timeline

nikic created this revision.Jan 3 2021, 12:13 PM
nikic requested review of this revision.Jan 3 2021, 12:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2021, 12:13 PM
nikic added inline comments.Jan 3 2021, 12:19 PM

A peculiar regression. Not sure how this folded before, but we're clearly missing a fold here: Poison can fold to poison: Undef can fold to base pointer: Undef can't fold to undef:

aqjune added inline comments.Jan 4 2021, 5:28 PM

The source program looks really interesting - it has gep with i1 index..!
I guess %G18 should have been folded like this:
gep %A2, i1 %C8 -> gep %A2, i1 undef -> gep %A2, i64 0 (by constfold sext undef) -> gep %A2
With poison, constfold sext poison is poison, hence it resulted in here.
I'll make a patch that makes gep poison -> poison.

aqjune added inline comments.Jan 4 2021, 6:10 PM
nikic updated this revision to Diff 314678.Jan 5 2021, 11:53 AM

Rebase over new gep poison fold.

aqjune accepted this revision.Jan 5 2021, 7:14 PM


This revision is now accepted and ready to land.Jan 5 2021, 7:14 PM
This revision was automatically updated to reflect the committed changes.