This is an archive of the discontinued LLVM Phabricator instance.

[X86] Cleanups and safety checks around the isFNEG
ClosedPublic

Authored by craig.topper on Jun 21 2019, 5:36 PM.

Details

Summary

This patch does a few things to start cleaning up the isFNEG function.

-Remove the Op0/Op1 peekThroughBitcast calls that seem unnecessary. getTargetConstantBitsFromNode has its own peekThroughBitcast inside. And we have a separate peekThroughBitcast on the return value.
-Add a check of the scalar size after the first peekThroughBitcast to ensure we haven't changed the element size and just did something like f32->i32 or f64->i64.
-Remove an unnecessary check that Op1's type is floating point after the peekThroughBitcast. We're just going to look for a bit pattern from a constant. We don't care about its type.
-Add VT checks on several places that consume the return value of isFNEG. Due to the peekThroughBitcasts inside, the type of the return value isn't guaranteed. So its not safe to use it to build other nodes without ensuring the type matches the type being used to build the node. We might be able to replace these checks with bitcasts instead, but I don't have a test case so a bail out check seemed better for now.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Jun 21 2019, 5:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2019, 5:36 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
RKSimon accepted this revision.Jun 24 2019, 4:21 AM

LGTM - as future work I've been wondering whether we should integrate this more with the isNegatibleForFree/GetNegatedExpression helpers in DAGCombine? A quick glance shows that several targets (X86, AMDGPU, ARM, AARCH64, SystemZ) all have very similar logic for generic and target-specific ops.

This revision is now accepted and ready to land.Jun 24 2019, 4:21 AM
This revision was automatically updated to reflect the committed changes.