This is an archive of the discontinued LLVM Phabricator instance.

[NFC] [DAGCombiner] Refactor bitcast folding within fabs/fneg
ClosedPublic

Authored by qiucf on Aug 31 2020, 12:56 AM.

Details

Summary

fabs and fneg share a common transformation:

(fneg (bitconvert x)) -> (bitconvert (xor x sign))
(fabs (bitconvert x)) -> (bitconvert (and x ~sign))

This patch separate the code into a single method.

Diff Detail

Event Timeline

qiucf created this revision.Aug 31 2020, 12:56 AM
qiucf requested review of this revision.Aug 31 2020, 12:56 AM
spatel added inline comments.Aug 31 2020, 5:27 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
21282–21283

Formatting nit: variables start with a capital letter, so "IsFNeg". But seeing the uses below, maybe this should be "IsFabs", so we don't have to use negative logic?

Also "Free" would be better as "IsFree".

21287

Invert this logic and early exit, so:

if (IsFree || ...) return SDValue();
21293–21294

These comments would be clearer if they said something like:

// Create a sign mask (0x80...) or its inverse (0x7f...).
qiucf updated this revision to Diff 288937.Aug 31 2020, 6:45 AM
qiucf marked 3 inline comments as done.

Address style comments.

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
13996

By the way, this can be removed since getNegatedExpression above already handles it?

spatel accepted this revision.Aug 31 2020, 7:11 AM

LGTM

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
13996

Yes, that seems likely. This code also doesn't handle vectors, so if you can confirm/add tests for those patterns, this should go away.

This revision is now accepted and ready to land.Aug 31 2020, 7:11 AM
This revision was automatically updated to reflect the committed changes.
qiucf marked an inline comment as done.
qiucf added inline comments.Aug 31 2020, 9:49 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
13996