This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Add an ISD::TRUNCATE to the legalization for ppc_is_decremented_ctr_nonzero
ClosedPublic

Authored by craig.topper on Jan 1 2018, 1:13 AM.

Details

Summary

I believe legalization is really expecting that ReplaceNodeResults will return something with the same type as the thing that's being legalized. Ultimately, it uses the output to replace the uses in the DAG so the type should match to make that work.

In this case the intrinsic returns i1 and the legalization promotes it to i32, but we need to return an i1, to insert a truncate back to i1. The new truncate will get added to worklist and end up being legalized itself, but won't require custom legalization.

With this fixed we can remove some code from PromoteIntRes_SETCC that seemed to only exist to deal with the intrinsic being replaced with a larger type without changing the other operand. With the truncate being used for connectivity this doesn't happen anymore.

Event Timeline

craig.topper created this revision.Jan 1 2018, 1:13 AM
hfinkel accepted this revision.Jan 6 2018, 8:28 PM

In this case the intrinsic returns i1 and the legalization promotes it to i32, but we need to return an i1, to insert a truncate back to i1. The new truncate will get added to worklist and end up being legalized itself, but won't require custom legalization.

It seems like there are two relevant cases. When crbits are enabled, then i1 is a legal type and getSetCCResultType should return i1. In this case, the truncate will be between i1 and i1 and should be removed (SelectionDAG::getNode does this). Otherwise, getSetCCResultType will be i32 and the legalizer will promote the truncate to be i32 -> i32 which will be similarly removed. Thus, this seems fine.

LGTM

This revision is now accepted and ready to land.Jan 6 2018, 8:28 PM
This revision was automatically updated to reflect the committed changes.