Skip to content

Commit

Permalink
ir/bits.h cleanups after #2879 (#3156)
Browse files Browse the repository at this point in the history
Improve some comments, and remove fast paths that are just optimizations for
compile time (code clarity matters more here).
  • Loading branch information
kripken authored Sep 22, 2020
1 parent b410773 commit 0f9339d
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions src/ir/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,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 @@ -199,12 +199,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 @@ -227,7 +223,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 @@ -255,7 +251,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 @@ -275,7 +271,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 @@ -293,17 +289,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 @@ -326,7 +318,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

0 comments on commit 0f9339d

Please sign in to comment.