Page MenuHomePhabricator

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

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

Details

Summary

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.Sun, Jan 3, 12:13 PM
nikic requested review of this revision.Sun, Jan 3, 12:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptSun, Jan 3, 12:13 PM
nikic added inline comments.Sun, Jan 3, 12:19 PM
llvm/test/Transforms/InstCombine/shift.ll
1723

A peculiar regression. Not sure how this folded before, but we're clearly missing a fold here: https://llvm.godbolt.org/z/89bah8 Poison can fold to poison: https://alive2.llvm.org/ce/z/7Nwdri Undef can fold to base pointer: https://alive2.llvm.org/ce/z/y6NLvJ Undef can't fold to undef: https://alive2.llvm.org/ce/z/emLp_H

aqjune added inline comments.Mon, Jan 4, 5:28 PM
llvm/test/Transforms/InstCombine/shift.ll
1723

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.Mon, Jan 4, 6:10 PM
llvm/test/Transforms/InstCombine/shift.ll
1723
nikic updated this revision to Diff 314678.Tue, Jan 5, 11:53 AM

Rebase over new gep poison fold.

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

LGTM

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