This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] fix and enhance udiv/urem narrowing
ClosedPublic

Authored by spatel on Aug 21 2017, 4:03 PM.

Details

Summary

There are 3 independent changes here, but I thought it would be easier to review one patch to handle them all. If it's better to review and/or commit separately, please let me know:

  1. Account for multiple uses in the pattern matching: avoid the transform if it increases the instruction count.
  2. Add a missing fold for the case where the numerator is the constant: http://rise4fun.com/Alive/E2p
  3. Enable all folds for vector types.

There's still one more potential change - use "shouldChangeType()" to keep from transforming to an illegal integer type.

Diff Detail

Repository
rL LLVM

Event Timeline

spatel created this revision.Aug 21 2017, 4:03 PM
craig.topper added inline comments.Aug 22 2017, 3:40 PM
lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
1103 ↗(On Diff #112080)

This is allowing arbitrary constant expressions through. Is that we want?

majnemer added inline comments.Aug 22 2017, 3:56 PM
lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
1103 ↗(On Diff #112080)

I don't see an issue with allowing ConstantExpr thru.

spatel added inline comments.Aug 22 2017, 4:09 PM
lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
1103 ↗(On Diff #112080)

The intent was of course to let arbitrary vector constants through, but it should work for constexpr too. I'll add a test to make sure.

spatel updated this revision to Diff 112252.Aug 22 2017, 4:13 PM

Patch updated:
No code changes, but added a test with a constexpr to show that's ok.

This revision is now accepted and ready to land.Aug 24 2017, 2:56 PM
This revision was automatically updated to reflect the committed changes.