This is an archive of the discontinued LLVM Phabricator instance.

[X86] Widen the 'AND' mask if doing so shrinks the encoding size
ClosedPublic

Authored by majnemer on Jul 17 2015, 1:28 AM.

Details

Summary

We can set additional bits in a mask given that we know the other
operand of an AND already has some bits set to zero. This can be more
efficient if doing so allows us to use an instruction which implicitly
sign extends the immediate.

This fixes PR24085.

Diff Detail

Repository
rL LLVM

Event Timeline

majnemer updated this revision to Diff 29982.Jul 17 2015, 1:28 AM
majnemer retitled this revision from to [X86] Widen the 'AND' mask if doing so shrinks the encoding size.
majnemer updated this object.
majnemer added a subscriber: llvm-commits.
majnemer updated this revision to Diff 29985.Jul 17 2015, 2:58 AM
  • Small cleanup
escha added inline comments.Jul 17 2015, 9:29 AM
lib/Target/X86/X86ISelDAGToDAG.cpp
2237 ↗(On Diff #29985)

Is this right? (int8_t)-384 would still pass this check, right?

majnemer added inline comments.Jul 17 2015, 10:20 AM
lib/Target/X86/X86ISelDAGToDAG.cpp
2237 ↗(On Diff #29985)

We wouldn't get that far because it would fail the above Val > 0 check.

chandlerc edited edge metadata.Jul 17 2015, 7:05 PM

Cool implementation. Some thoughts inline about structuring the code a bit better.

lib/Target/X86/X86ISelDAGToDAG.cpp
2226–2230 ↗(On Diff #29985)

At this point, I think it would be worth extracting this to a helper function. That will let you use early-exit to make everything easier to read IMO.

2251–2269 ↗(On Diff #29985)

I would put all of this into a lambda that you can call with the number of bits, the MVT, and the opcode. It should be easier to read, and make the above tests able to just return the call of the lambda each time they find a valid opcode.

majnemer updated this revision to Diff 30072.Jul 17 2015, 11:33 PM
majnemer edited edge metadata.
  • Small cleanup
  • Address review comments

Ugh. The lambda didn't help as much as i had hoped because you need to only compute the known bits once. Unfortunate.

lib/Target/X86/X86ISelDAGToDAG.cpp
2145–2146 ↗(On Diff #30072)

uint64_t(...) <= 0? Why not just == 0, or did you mean something else?

Ugh. The lambda didn't help as much as i had hoped because you need to only compute the known bits once. Unfortunate.

Is it still worth keeping the lambda?

lib/Target/X86/X86ISelDAGToDAG.cpp
2145–2146 ↗(On Diff #30072)

It's a victim of refactoring. Val should be int64_t.

majnemer updated this revision to Diff 30075.Jul 18 2015, 12:43 AM
  • Fix a bug introduced during refactoring.
chandlerc accepted this revision.Jul 18 2015, 1:24 AM
chandlerc edited edge metadata.

LGTM

I'd just leave the code as is.

If you can come up with tests that would tickle the int64_t and int8_t case, it'd be nice to add those.

This revision is now accepted and ready to land.Jul 18 2015, 1:24 AM
This revision was automatically updated to reflect the committed changes.