Page MenuHomePhabricator

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

Authored by nikic on Jan 3 2021, 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.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
llvm/test/Transforms/InstCombine/shift.ll
1724

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.Jan 4 2021, 5:28 PM
llvm/test/Transforms/InstCombine/shift.ll
1724

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
llvm/test/Transforms/InstCombine/shift.ll
1724
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

LGTM

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.