This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] visitShiftByConstant(): drop bogus(?) signbit check
ClosedPublic

Authored by lebedev.ri on May 14 2019, 2:44 PM.

Details

Summary

That check claims that the transform is illegal otherwise.
That isn't true:

  1. For ISD::ADD, we only process ISD::SHL outer shift => sign bit does not matter https://rise4fun.com/Alive/K4A
  2. For ISD::AND, there is no restriction on constants: https://rise4fun.com/Alive/Wy3
  3. For ISD::OR, there is no restriction on constants: https://rise4fun.com/Alive/GOH
  4. For ISD::XOR, there is no restriction on constants: https://rise4fun.com/Alive/ml6

So, why is it there then?

This changes the testcase that was touched by @spatel in rL347478,
but i'm not sure that test tests anything particular?

Diff Detail

Repository
rL LLVM

Event Timeline

lebedev.ri created this revision.May 14 2019, 2:44 PM

(adding reviewers from D27916)

This logic was copied from canShiftBinOpWithConstantRHS in InstCombineShifts.cpp

This logic was copied from canShiftBinOpWithConstantRHS in InstCombineShifts.cpp

Aha, that makes sense. Posted D61938.

spatel added inline comments.May 15 2019, 10:01 AM
test/CodeGen/X86/xor.ll
496–498 ↗(On Diff #199516)

This test (and the 1 below here) wasn't resulting in 'not' asm before rL347478, so I was trying to make that happen.

This diff seems like a (slight) regression because we're turning a 32-bit 'not' into a 64-bit 'not' (extra prefix byte?), but I'm not sure if anyone cares.

Now with tests.

This logic was copied from canShiftBinOpWithConstantRHS in InstCombineShifts.cpp

Aha, that makes sense. Posted D61938.

Does this look good now that this fix for the origin of this code is accepted?

spatel accepted this revision.May 17 2019, 5:47 AM

LGTM - might want to leave a 'TODO' comment for the x86 test that can use the narrower 'not' instruction.

This revision is now accepted and ready to land.May 17 2019, 5:47 AM