This is an archive of the discontinued LLVM Phabricator instance.

[X86] Integer multiplication improvements
Needs ReviewPublic

Authored by mkuper on Feb 1 2015, 6:04 AM.

Details

Reviewers
nadav
delena
Summary

This makes the x86-specific DAG combine for (imul -> shl + lea) more generic, allowing it to handle some cases it could not handle before (e.g. x * -81 or x * 1920).

Diff Detail

Event Timeline

mkuper updated this revision to Diff 19111.Feb 1 2015, 6:04 AM
mkuper retitled this revision from to [X86] Integer multiplication improvements.
mkuper updated this object.
mkuper edited the test plan for this revision. (Show Details)
mkuper added reviewers: nadav, delena.
mkuper added a subscriber: Unknown Object (MLST).
chandlerc added inline comments.
lib/Target/X86/X86ISelLowering.cpp
23991–23992

s/in/an

24019–24023

This doesn't really make sense. We shouldn't be hard coding these things here.

  • LEA as slower on Atom than on other X86 chips.
  • IMUL can be anything from 6 to 14 cycles on some X86 chips.

We have a schedule, we should consult it for the expected latency of these and use those to drive the limits. (And we should fix the schedule to be correct if it is currently wrong.)

Also, I wouldn't use capitals here. This isn't a macro.

24025–24026

Just use the boolean?

24060–24061

It's pretty hostile to the DAG to create nodes unless they are absolutely going to be used. It's almost certainly better to do the math in a tight loop first to verify that we'll actually combine this node.

That will also let you use early exit.

mkuper added a comment.Feb 1 2015, 7:29 AM

Thanks, Chandler!

lib/Target/X86/X86ISelLowering.cpp
24019–24023

Right, didn't think about Atom, I'll check whether it's worthwhile there, thanks!

The "4" is just a conservative estimate - precisely because it can be anything in a fairly large range (can be below 6 - starts at 4 on HSW). I don't think we model that anywhere, so taking a number from the schedule didn't look like the right thing to do. In any case, I'll take a look at what the schedule currently is, and whether it makes sense.

24025–24026

I always thought adding a boolean looks odd, but sure.

24060–24061

Got it.

lib/Target/X86/X86ISelLowering.cpp