-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[AVR] Fix codegen after getConstant assertions got enabled #152269
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for the quick review @benshi001! @RKSimon can you also take a look, to be sure? |
@@ -713,7 +713,7 @@ SDValue AVRTargetLowering::getAVRCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, | |||
// Turn lhs < rhs with lhs constant into rhs >= lhs+1, this allows us to | |||
// fold the constant into the cmp instruction. | |||
if (const ConstantSDNode *C = dyn_cast<ConstantSDNode>(RHS)) { | |||
RHS = DAG.getConstant(C->getSExtValue() + 1, DL, VT); | |||
RHS = DAG.getSignedConstant(C->getSExtValue() + 1, DL, VT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be DAG.getConstant(C->getZExtValue() + 1, DL, VT);
its an unsigned compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you are right. I changed it to getConstant
and getZExtValue
and it works (both the test I added and all TinyGo AVR tests pass with this patch applied).
I also added an assert to make sure the addition won't unintentionally overflow.
77d8426
to
25b860b
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
This fixes llvm#152097 This commit fixes two instances of a (somewhat) recently enabled assertion. One with a test, the other I can't reproduce (might be dead code) but certainly looks like an instance of the same problem. The PR that introduced the regression: llvm#117558
25b860b
to
9391850
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Requested a backport for 21.x in #152679 |
This fixes #152097
This commit fixes two instances of a (somewhat) recently enabled assertion. One with a test, the other I can't reproduce (might be dead code) but certainly looks like an instance of the same problem.
The PR that introduced the regression: #117558
With this patch, the AVR backend is usable again for TinyGo.