This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG] Handle non-power-of-2 bitwidths in expandROT
ClosedPublic

Authored by foad on Aug 24 2020, 5:34 AM.

Diff Detail

Event Timeline

foad created this revision.Aug 24 2020, 5:34 AM
foad requested review of this revision.Aug 24 2020, 5:34 AM
xbolva00 retitled this revision from Summary: [SelectionDAG] Handle non-power-of-2 bitwidths in expandROT to [SelectionDAG] Handle non-power-of-2 bitwidths in expandROT.Aug 24 2020, 5:38 AM
RKSimon added inline comments.Aug 25 2020, 2:22 AM
llvm/test/CodeGen/WebAssembly/fshl.ll
4

move the triple into the run command?

6

Please can you add a comment referencing the ossfuzz url?

foad updated this revision to Diff 287601.Aug 25 2020, 2:37 AM

Add a comment.

foad marked an inline comment as done.Aug 25 2020, 2:38 AM
foad added inline comments.
llvm/test/CodeGen/WebAssembly/fshl.ll
4

Could do but why? That is definitely not the prevailing style in test/CodeGen/WebAssembly/.

Do we guarantee that the rotate amount is not undef? (Can we assert that?)
The expansion may fail if the rotate amount is 'undef':
https://alive2.llvm.org/ce/z/tqjuC7

llvm/test/CodeGen/WebAssembly/fshl.ll
4

This should be fine. Specifying the target in the IR is the default.
Over in x86, we tend to prefer to put it on the RUN line because we have many tests that vary the subtarget slightly...because there are so many HW variations to think about.

Can we pre-commit the test before this patch with a FIXME note? This is currently miscompiling?

nikic added a subscriber: nikic.Aug 25 2020, 1:50 PM

Do we guarantee that the rotate amount is not undef? (Can we assert that?)
The expansion may fail if the rotate amount is 'undef':
https://alive2.llvm.org/ce/z/tqjuC7

Undef is a legal rotate amount (because we spec rotate to be modulo the bitwidth, unlike normal shifts, where it is poison). However, I don't think it makes sense to consider undef-related issues at the SDAG layer at this point in time. They are much less likely to cause practical miscompiles here, and it's much harder to be undef-correct in SDAG (because expansion and legalization will often introduce multiple uses of the values, with the issues that may entail, as in this case). Being pedantic about this would need a lot of FREEZE.

spatel accepted this revision.Aug 25 2020, 2:42 PM

Do we guarantee that the rotate amount is not undef? (Can we assert that?)
The expansion may fail if the rotate amount is 'undef':
https://alive2.llvm.org/ce/z/tqjuC7

Undef is a legal rotate amount (because we spec rotate to be modulo the bitwidth, unlike normal shifts, where it is poison). However, I don't think it makes sense to consider undef-related issues at the SDAG layer at this point in time. They are much less likely to cause practical miscompiles here, and it's much harder to be undef-correct in SDAG (because expansion and legalization will often introduce multiple uses of the values, with the issues that may entail, as in this case). Being pedantic about this would need a lot of FREEZE.

Yes, I agree that we don't want to take undef in codegen too seriously. We may want to add that fold for safety though because it seems to survive on most targets here.

And I see now that we are currently crashing on this example (on all targets?), so we need to get this fixed ASAP.
LGTM.

This revision is now accepted and ready to land.Aug 25 2020, 2:42 PM
This revision was automatically updated to reflect the committed changes.
RKSimon added inline comments.Aug 26 2020, 2:33 AM
llvm/test/CodeGen/WebAssembly/fshl.ll
4

Yeah - don't worry, its just I'm so used to it I think it looks tidier these days.... </OCD>

spatel added inline comments.Aug 26 2020, 3:32 AM
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
6261

This can't be right - both shifts are HsOpc. We need another test with a variable shift amount to make sure this is correct?

foad added inline comments.Aug 26 2020, 3:34 AM
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
6261

It's correct. We want to shift by 1..32, so we do a shift by 1 and then a shift by 0..31.

spatel added inline comments.Aug 26 2020, 3:35 AM
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
6261

Oops, disregard. Too early in the AM. :)