This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG] TargetLowering::SimplifyDemandedBits how to properly calculate KnownZero bits for ISD::SETCC and ISD::AssertZExt
ClosedPublic

Authored by craig.topper on Apr 5 2017, 10:06 AM.

Details

Summary

For SETCC we aren't calculating the KnownZero bits at all. I've copied the code from computeKnownZero over for this.

For AssertZExt we were only setting KnownZero for bits that were demanded. But the upper bits are zero whether they were demanded or not.

I'm interested in fixing this because my belief is the first part of the ISD::AND handling code in SimplifyDemandedBits largely exists because of these two bugs. In that code we go to computeKnownBits for the LHS and optimize a RHS constant. Because computeKnownBits handles SETCC and AssertZExt correctly we get better information sometimes than when we call SimplifyDemandedBits on the LHS later. With these two issues fixed in SimplifyDemandedBits I was able to remove that computeKnownBits call and still pass all X86 tests. I'll submit that change in a separate patch.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Apr 5 2017, 10:06 AM
RKSimon added inline comments.Apr 5 2017, 10:55 AM
lib/CodeGen/SelectionDAG/TargetLowering.cpp
794 ↗(On Diff #94253)

Use Op0 directly?

Addressed Simon's comment.

craig.topper marked an inline comment as done.Apr 5 2017, 12:14 PM
RKSimon added inline comments.Apr 6 2017, 5:21 AM
lib/CodeGen/SelectionDAG/TargetLowering.cpp
794 ↗(On Diff #94253)

Come to think of it - why are you testing the input op type and not the result type (Op.getValueType()) like above?

craig.topper added inline comments.Apr 6 2017, 9:21 AM
lib/CodeGen/SelectionDAG/TargetLowering.cpp
794 ↗(On Diff #94253)

I sort of wondered that too, but I just copied the code out of computeKnownBits

RKSimon added inline comments.Apr 7 2017, 8:52 AM
lib/CodeGen/SelectionDAG/TargetLowering.cpp
794 ↗(On Diff #94253)

I think this needs fixing first - I made the change in computeKnownBits and it affected a number of MIPS tests - I'll have a look at what is going on.

RKSimon accepted this revision.Apr 7 2017, 9:07 AM

LGTM

lib/CodeGen/SelectionDAG/TargetLowering.cpp
794 ↗(On Diff #94253)

False alarm - it's doing what its supposed to and is using the input type correctly to call TLI::getBooleanContents

This revision is now accepted and ready to land.Apr 7 2017, 9:07 AM
This revision was automatically updated to reflect the committed changes.