This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG] Add LegalTypes flag to getShiftAmountTy. Use it to unify and simplify DAGCombiner and simplifySetCC code and fix a bug.
ClosedPublic

Authored by craig.topper on Feb 18 2018, 4:52 PM.

Details

Summary

DAGCombiner and SimplifySetCC both use getPointerTy for shift amounts pre-legalization. DAGCombiner uses a single helper function to hide this. SimplifySetCC does it in multiple places.

This patch adds a defaulted parameter to getShiftAmountTy that can make it return getPointerTy for scalar types. Use this parameter to simplify the SimplifySetCC and DAGCombiner.

Additionally, there were two places in SimplifySetCC that were creating shifts using the target's preferred shift amount pre-legalization. If the target uses a narrow type and the type is illegal, this can cause SimplfiySetCC to create a shift with an amount that can't represent all possible shift values for the type. To fix this we should use pointer type there too.

Alternatively we could make getScalarShiftAmountTy for each target return a safe value for large types as proposed in D43445. And maybe we should still do that, but fixing the SimplifySetCC code keeps other targets from tripping over this in the future.

Fixes PR36250.

Diff Detail

Event Timeline

craig.topper created this revision.Feb 18 2018, 4:52 PM
RKSimon accepted this revision.Feb 20 2018, 2:02 AM

LGTM - still don't understand why we don't have a single overidable function instead of the getShiftAmountTy/getScalartShiftAmountTy duplication.

This revision is now accepted and ready to land.Feb 20 2018, 2:02 AM
This revision was automatically updated to reflect the committed changes.