Skip to content
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

Add ((id+/-e)+/-id) simplification rule #1268

Merged
merged 2 commits into from
Jul 23, 2023
Merged

Conversation

ptomin
Copy link
Collaborator

@ptomin ptomin commented Jul 16, 2023

No description provided.

@ptomin ptomin self-assigned this Jul 16, 2023
@ptomin ptomin added the enhancement This is a feature request label Jul 16, 2023
@ptomin ptomin requested a review from uxmal July 16, 2023 07:23
Copy link
Owner

@uxmal uxmal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some regressions, which need to be addressed.

binLeft.Left, binExp.Right),
binLeft.Right);
return (binExp, true);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a safe transformation when taking unsigned or signed overflow into account? I refer to the regression suite, where several subjects have regressed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, (id + e) - id is always e. Given id=0xffffffff , e = 1, (0xffffffff + 1) = 0, (0 - 0xffffffff) = 1. But I need to do more detailed testing on mentioned samples. Maybe there are problems at other rules.

@@ -17161,7 +17161,7 @@ byte fn0000EB48(Eq_n r0, Eq_n r1, ui32 r2, struct Eq_n * r3, Eq_n r4, Eq_n r5, s
if (r2_n <= r5_n)
{
r2_n.u0 = r5_n.u0 + 1;
if (r5_n.u0 + 1 < r5_n)
if (false)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a saturated add: first check for unsigned overflow, and if so, force the value to 0xFFFFFFFF. This regression cannot be allowed.

@@ -193,7 +193,7 @@ int32 fn0000275C(struct Eq_n * a0, struct Eq_n * a5, struct Eq_n & a0Out)
a5->ptrFFFFFAD0 = a0;
struct Eq_n * d0_n = a0;
struct Eq_n * d1_n = (char *) &a0->t0004 + 4;
if (&a0->dw0FF8 > a0)
if (true)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a regression that needs addressing.

It's unsafe to simplify 'cond(e)'. This operation actually requires flags of
expression, not expression itseft. So ConditionCodeEliminator should do its
work before. For instance we have cond(x - y) where x = y + 1 and can't
simplify it to cond((y + 1) - y) => cond(1). 'y + 1 > y' can be used as test
for overflow.
@ptomin ptomin force-pushed the id-e-id-rule branch 2 times, most recently from 55d58e8 to 559c92a Compare July 22, 2023 21:01
@uxmal uxmal merged commit 6fa0a00 into uxmal:master Jul 23, 2023
4 checks passed
@ptomin ptomin deleted the id-e-id-rule branch July 24, 2023 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is a feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants