This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Do not fold 'and (sext (ashr X, Shift)), C' if Shift < 0
ClosedPublic

Authored by BertalanD on Jul 7 2022, 9:32 AM.

Details

Reviewers
fhahn
spatel
Summary

The 'and (sext (ashr X, ShiftC)), C' --> 'lshr (sext X), ShiftC'
transformation would access out of bounds bits in APInt::getLowBitsSet
if the shift count was larger than X's bit width or negative.

Fixes #56424

Diff Detail

Event Timeline

BertalanD created this revision.Jul 7 2022, 9:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2022, 9:32 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
BertalanD requested review of this revision.Jul 7 2022, 9:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2022, 9:32 AM
fhahn accepted this revision.Jul 7 2022, 9:35 AM

LGTM, thanks!

llvm/test/Transforms/InstCombine/pr56424.ll
3

might be worth to switch to the new pass manager syntax (-passes=instcombine)

6

could you name the arguments instead of having them implicitly numbered?

This revision is now accepted and ready to land.Jul 7 2022, 9:35 AM
spatel added inline comments.Jul 7 2022, 9:39 AM
llvm/test/Transforms/InstCombine/pr56424.ll
6

Nit: I find it a little easier for subsequent bug-hunting and archaeology if you put this test next to the existing tests for the buggy fold.
You can then name the test @PR56424 and/or put a link to the issue in the test comment.

BertalanD updated this revision to Diff 442964.Jul 7 2022, 9:54 AM

Added a link to the issue, switched to the new PM syntax and named the arguments.

Thank you for the review

BertalanD closed this revision.Jul 7 2022, 10:16 AM

Whoops, totally forgot about the "Differential Revision:" trailer, sorry. Committed as ef7aed3e112b47641ca2704187d3701765a831ce.

Added a link to the issue, switched to the new PM syntax and named the arguments.

Thank you for the review

My suggestion was to add the test around here rather than create a new file for just this one test:
https://github.com/llvm/llvm-project/blob/ef7aed3e112b47641ca2704187d3701765a831ce/llvm/test/Transforms/InstCombine/and.ll#L1362

BertalanD added a comment.EditedJul 7 2022, 10:25 AM

My suggestion was to add the test around here rather than create a new file for just this one test:
https://github.com/llvm/llvm-project/blob/ef7aed3e112b47641ca2704187d3701765a831ce/llvm/test/Transforms/InstCombine/and.ll#L1362

Argh, today's not my day then 🤦

My suggestion was to add the test around here rather than create a new file for just this one test:
https://github.com/llvm/llvm-project/blob/ef7aed3e112b47641ca2704187d3701765a831ce/llvm/test/Transforms/InstCombine/and.ll#L1362

Argh, today's not my day then 🤦

Not a big deal - the bug fix is the more important part and looks good. :)