This is an archive of the discontinued LLVM Phabricator instance.

[APInt] Add ashrInPlace method and rewrite in ashr using it.
ClosedPublic

Authored by craig.topper on Apr 23 2017, 10:49 PM.

Details

Summary

This patch adds an in place version of ashr to match lshr and shl which were recently added.

I've tried to make this similar to the lshr code with additions to handle the sign extension. I've also tried to do this with less if checks than the current ashr code by sign extending the original result to a word boundary before doing any of the shifting. This removes a lot of the complexity of determining where to fill in sign bits after the shifting.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Apr 23 2017, 10:49 PM
hans accepted this revision.Apr 24 2017, 10:08 AM

lgtm with some comments

include/llvm/ADT/APInt.h
911 ↗(On Diff #96345)

What does the "// undefined" comment mean? That we don't really define what happens when ShiftAmt == BitWidth but we try to do something reasonable? Maybe spell that out, I hadn't seen that before.

lib/Support/APInt.cpp
1029 ↗(On Diff #96345)

Maybe this should be inline since it's so simple?

1039 ↗(On Diff #96345)

Did you lose the "Invalid shift amount" assert?

1043 ↗(On Diff #96345)

nit: "is is intra-part shift"

1051 ↗(On Diff #96345)

Maybe run clang-format on this line? There should usually be spaces around the '-' operator for example.

1060 ↗(On Diff #96345)

nit: spaces around the - here too

This revision is now accepted and ready to land.Apr 24 2017, 10:08 AM
craig.topper added inline comments.Apr 24 2017, 10:19 AM
lib/Support/APInt.cpp
1029 ↗(On Diff #96345)

Possibly. Though both ashrInPlace and getLimitedValue will expand to include slow case calls.

All 3 shifts types have this out of line so I'll look at them together.

1039 ↗(On Diff #96345)

It was moved to the inline single word case.

1043 ↗(On Diff #96345)

Seems that tcShiftRight and tcShiftLeft have the same mistake. Thanks!

This revision was automatically updated to reflect the committed changes.