This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC32] Fix the `setcc` inconsistent result type problem
ClosedPublic

Authored by daltenty on Mar 5 2020, 10:55 AM.

Details

Summary

On 32-bit PPC target[AIX and BE], when we convert an i64 to f32, a setcc operand expansion is needed. The expansion will set the result type of expanded setcc operation based on if the subtarget use CRBits or not. If the subtarget does use the CRBits, like AIX and BE, then it will set the result type to i1, leading to an inconsistency with original setcc result type[i32].
And the reason why it crashed underneath is because we don't set result type of setcc consistent in those two places.

This patch fixes this problem by setting original setcc opnode result type also with getSetCCResultType interface.

Diff Detail

Event Timeline

Xiangling_L created this revision.Mar 5 2020, 10:55 AM

I get why you named the test ppc32-setcc-expansion.ll but to a casual reader its definitely unclear what a setcc has to do with this code. I would suggest 'ppc32-i64-to-float-conv.ll', and have a comment explaining how the lowering for the conversion generates a setcc which caused a crash under certain conditions.

Also does the IR that inspired this patch work when CR-bits are disabled (if we can disable them)? If so we should verify it works after the change also.

llvm/lib/Target/PowerPC/PPCISelLowering.cpp
8154–8157

You are on the right track but I think getSetCCResultType is the interface we want to use to get the proper result type. FWIW it will be the same behavior but somewhat self documenting.

Xiangling_L retitled this revision from [PowerPC32] Fix the setcc unexpected expansion problem to [PowerPC32] Fix the `setcc` inconsistent result type problem.Mar 6 2020, 9:04 AM
Xiangling_L edited the summary of this revision. (Show Details)
Xiangling_L marked 2 inline comments as done.

Update to use the getSetCCResultType interface to get setcc result type;
Update the testcase name and add a description to make the testcase's purpose clearer;

sfertile accepted this revision.Mar 6 2020, 11:24 AM

1 minor comment but otherwise LGTM.

llvm/lib/Target/PowerPC/PPCISelLowering.cpp
8155

The EVT passed in should be Cond.getValueType(), or a hard coded MVT::i64.

This revision is now accepted and ready to land.Mar 6 2020, 11:24 AM
daltenty commandeered this revision.Mar 12 2020, 7:45 AM
daltenty added a reviewer: Xiangling_L.
daltenty marked an inline comment as done.
This revision was automatically updated to reflect the committed changes.