Skip to content

bits.h cleanups after #2879 #3156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions src/ir/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Index getMaxBits(Expression* curr,
case RemSInt32: {
if (auto* c = binary->right->dynCast<Const>()) {
auto maxBitsLeft = getMaxBits(binary->left, localInfoProvider);
// if maxBitsLeft is negative
// if left may be negative, the result may be negative
if (maxBitsLeft == 32) {
return 32;
}
Expand All @@ -200,12 +200,8 @@ Index getMaxBits(Expression* curr,
}
case OrInt32:
case XorInt32: {
auto maxBits = getMaxBits(binary->right, localInfoProvider);
// if maxBits is negative
if (maxBits == 32) {
return 32;
}
return std::max(getMaxBits(binary->left, localInfoProvider), maxBits);
return std::max(getMaxBits(binary->left, localInfoProvider),
getMaxBits(binary->right, localInfoProvider));
}
case ShlInt32: {
if (auto* shifts = binary->right->dynCast<Const>()) {
Expand All @@ -228,7 +224,7 @@ Index getMaxBits(Expression* curr,
case ShrSInt32: {
if (auto* shift = binary->right->dynCast<Const>()) {
auto maxBits = getMaxBits(binary->left, localInfoProvider);
// if maxBits is negative
// if left may be negative, the result may be negative
if (maxBits == 32) {
return 32;
}
Expand Down Expand Up @@ -256,7 +252,7 @@ Index getMaxBits(Expression* curr,
case DivSInt64: {
if (auto* c = binary->right->dynCast<Const>()) {
int32_t maxBitsLeft = getMaxBits(binary->left, localInfoProvider);
// if maxBitsLeft or right const value is negative
// if left or right const value is negative
if (maxBitsLeft == 64 || c->value.geti64() < 0) {
return 64;
}
Expand All @@ -276,7 +272,7 @@ Index getMaxBits(Expression* curr,
case RemSInt64: {
if (auto* c = binary->right->dynCast<Const>()) {
auto maxBitsLeft = getMaxBits(binary->left, localInfoProvider);
// if maxBitsLeft is negative
// if left may be negative, the result may be negative
if (maxBitsLeft == 64) {
return 64;
}
Expand All @@ -294,17 +290,13 @@ Index getMaxBits(Expression* curr,
return 64;
}
case AndInt64: {
auto maxBits = getMaxBits(binary->right, localInfoProvider);
return std::min(getMaxBits(binary->left, localInfoProvider), maxBits);
return std::min(getMaxBits(binary->left, localInfoProvider),
getMaxBits(binary->right, localInfoProvider));
}
case OrInt64:
case XorInt64: {
auto maxBits = getMaxBits(binary->right, localInfoProvider);
// if maxBits is negative
if (maxBits == 64) {
return 64;
}
return std::max(getMaxBits(binary->left, localInfoProvider), maxBits);
return std::max(getMaxBits(binary->left, localInfoProvider),
getMaxBits(binary->right, localInfoProvider));
}
case ShlInt64: {
if (auto* shifts = binary->right->dynCast<Const>()) {
Expand All @@ -327,7 +319,7 @@ Index getMaxBits(Expression* curr,
case ShrSInt64: {
if (auto* shift = binary->right->dynCast<Const>()) {
auto maxBits = getMaxBits(binary->left, localInfoProvider);
// if maxBits is negative
// if left may be negative, the result may be negative
if (maxBits == 64) {
return 64;
}
Expand Down