This is an archive of the discontinued LLVM Phabricator instance.

Fix SystemZ compilation abort caused by negative AND mask
ClosedPublic

Authored by colpell on Aug 16 2016, 9:05 AM.

Details

Reviewers
uweigand
Summary

Normally, when an AND with a constant is lowered to NILL, the constant value is truncated to 16 bits. However, since r274066, ANDs whose results are used in a shift are caught by a different pattern that does not truncate. The instruction printer expects a 16-bit unsigned immediate operand for NILL, so this results in an abort.

This patch adds code to manually truncate the constant in this situation. The rest of the bits are then set, so we will detect a case for NILL "naturally" rather than using peephole optimizations.

Diff Detail

Event Timeline

colpell updated this revision to Diff 68196.Aug 16 2016, 9:05 AM
colpell retitled this revision from to Fix SystemZ compilation abort caused by negative AND mask.
colpell updated this object.
colpell added a reviewer: uweigand.
colpell added a subscriber: llvm-commits.
uweigand edited edge metadata.Aug 17 2016, 8:20 AM

I agree it makes sense to do this transformation in PerformDAGCombine. Patch looks good to me.

However, once we do this here, aren't the peepholes in SystemZInstrInfo.td now superfluous? If so, they should be removed again ...

Also, please update the comment before combineSHIFTROT so it matches the new behaviour of the routine.

colpell updated this revision to Diff 68370.Aug 17 2016, 8:55 AM
colpell edited edge metadata.

Update combineSHIFTROT comment.

This patch truncates the constant to 16 bits, but the actual optimization of using NILL instead of NILF is still covered by the peepholes in SystemZInstrInfo.td. If those peepholes are removed, then we still end up using NILF in cases where we could have used NILL.

This patch truncates the constant to 16 bits, but the actual optimization of using NILL instead of NILF is still covered by the peepholes in SystemZInstrInfo.td. If those peepholes are removed, then we still end up using NILF in cases where we could have used NILL.

Ah, I see. In this case, I think the best way would be to, instead of truncating the constant, making sure the high bits are *set*, so that instruction selection will then prefer NILL automatically ...

colpell updated this revision to Diff 68392.Aug 17 2016, 11:49 AM
colpell updated this object.

Agreed, that's a better approach.

jonpa added a subscriber: jonpa.Aug 17 2016, 10:53 PM
uweigand accepted this revision.Aug 18 2016, 5:55 AM
uweigand edited edge metadata.

LGTM, thanks!

This revision is now accepted and ready to land.Aug 18 2016, 5:55 AM
colpell closed this revision.Aug 18 2016, 2:01 PM

Accidentally pointed the commit to the wrong differential revision:
https://reviews.llvm.org/rL279105