This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner][TLI] SimplifySetCC(): recanonicalize `(X&1) != 0` (PR51312)
AbandonedPublic

Authored by lebedev.ri on Aug 3 2021, 4:01 PM.

Details

Summary

(x&1)==1 is not canonical, and we'd canonicalize it to (x&1)!=0 already,
but that excludes it from a few folds, which eventually leads to a worse codegen.
This essentially fixes a regression after we started to canonicalize
add/xor reductions w/ i1 element type to a parity check.

Diff Detail

Event Timeline

lebedev.ri created this revision.Aug 3 2021, 4:01 PM
lebedev.ri requested review of this revision.Aug 3 2021, 4:01 PM
craig.topper added inline comments.Aug 3 2021, 4:17 PM
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
3875

Does this renormalize only happen if VT doesn't match Op0.getValueType()?

llvm/test/CodeGen/SystemZ/int-cmp-47.ll
270

Is this a regression?

llvm/test/CodeGen/X86/parity-vec.ll
66

Is this a different issue?

lebedev.ri added a subscriber: uweigand.
lebedev.ri added inline comments.
llvm/test/CodeGen/SystemZ/int-cmp-47.ll
270

@uweigand - suggestions on how to avoid this? (i guess this was initially added in rL195473)

lebedev.ri marked an inline comment as done.Aug 3 2021, 4:28 PM
lebedev.ri added inline comments.
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
3875

Yes, and i've guarded against infinite looping via if (N1C->isOne() || Op0 != OrigOp0) {

lebedev.ri abandoned this revision.Aug 3 2021, 4:49 PM
lebedev.ri marked an inline comment as done.

Actually, let's not.

llvm/test/CodeGen/X86/parity-vec.ll
66

It's similar in a way, here we need (x&1)^1 or x^1.
But allowing Cond == ISD::SETNE results in a swamp of regressions.,
with a few wins. Perhaps that highlights that the approach is wrong.