Closed
Bug 642535
Opened 14 years ago
Closed 14 years ago
CodegenLIR incorrectly uses LIR_divi to divide unsigned values, giving incorrect results.
Categories
(Tamarin Graveyard :: Baseline JIT (CodegenLIR), defect)
Tamarin Graveyard
Baseline JIT (CodegenLIR)
Tracking
(Not tracked)
RESOLVED
FIXED
Q3 11 - Serrano
People
(Reporter: sold2, Assigned: wmaddox)
References
Details
(Whiteboard: WE:2831430,has-patch,fixed-in-wasabi,fixed-in-tamarin)
Attachments
(5 files)
(deleted),
text/plain
|
Details | |
(deleted),
patch
|
edwsmith
:
review+
|
Details | Diff | Splinter Review |
Avoid using LIR_divi on unsigned integers. Also, protect against LIR_divi on two constant arguments.
(deleted),
patch
|
rreitmai
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
edwsmith
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
rreitmai
:
review+
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)
Build Identifier:
The implementation of LIR_divi doesn't handle unsigned operands correctly (other than for power-of-two divisors, which are lowered into shifts), and uses signed division exclusively. This gives wrong results when the signed interpretation of the operand(s) is negative.
Reproducible: Always
Comment 1•14 years ago
|
||
LIR_divi is only for signed division. Maybe the bug is tamarin's frontend generating LIR_divi for unsigned values? do you have a test case?
var x : uint = 0xffffffff;
x /= 3;
trace(x);
This code calculates -1 / 3 which is 0.
Make sure to run this with -Ojit, as the interpreter gives the correct result.
Updated•14 years ago
|
Blocks: interp_jit_semantics
(In reply to comment #1)
> LIR_divi is only for signed division. Maybe the bug is tamarin's frontend
> generating LIR_divi for unsigned values? do you have a test case?
Yeah, this is what I meant. Sorry for the unclearity.
No longer blocks: interp_jit_semantics
Comment 4•14 years ago
|
||
> Yeah, this is what I meant. Sorry for the unclearity.
No problem. I can reproduce in TR, wow, talk about a hole in the test suite.
Hardware: x86 → All
Target Milestone: --- → Q2 11 - Wasabi
Updated•14 years ago
|
Status: UNCONFIRMED → NEW
Ever confirmed: true
Updated•14 years ago
|
Summary: LIR_divi gives incorrect results for unsigned values → CodegenLIR incorrectly uses LIR_divi to divide unsigned values, giving incorrect results.
Updated•14 years ago
|
Updated•14 years ago
|
Blocks: interp_jit_semantics
Comment 5•14 years ago
|
||
This was injected by bug 600585, in this change:
http://hg.mozilla.org/tamarin-redux/rev/5512
Comment 6•14 years ago
|
||
(In reply to comment #5)
> This was injected by bug 600585, in this change:
> http://hg.mozilla.org/tamarin-redux/rev/5512
Correction, looks like this change did it:
http://hg.mozilla.org/tamarin-redux/rev/5395
bug 570476. Support integer division (minus NJ part). (+r wmaddox)
Assignee | ||
Updated•14 years ago
|
Assignee: nobody → wmaddox
Updated•14 years ago
|
Attachment #519978 -
Attachment mime type: application/octet-stream → text/plain
Assignee | ||
Comment 7•14 years ago
|
||
Attachment #520004 -
Flags: review?(edwsmith)
Comment 8•14 years ago
|
||
Comment on attachment 520004 [details] [diff] [review]
Avoid using LIR_divi on unsigned integers
This part looks right, but do we already do the right thing when everything is a constant? Also, needs a test case.
Attachment #520004 -
Flags: review?(edwsmith) → review+
Updated•14 years ago
|
Flags: flashplayer-injection+
Flags: flashplayer-bug+
Assignee | ||
Comment 9•14 years ago
|
||
Nanojit asserts if LIR_divi is used with constant arguments, and there is a comment to the effect that front-ends should not emit such code. (The restriction exists for the sake of the divi/modi hack.) There is no ABC divide_i operator -- conceptually, all division produces a Number result, and I've experimentally verified that expressions that attempt to divide integer constants convert to doubles and fold the double division. For example, the following abcasm program:
function main()
{
getlocal0
pushscope
findpropstrict print
pushint 555
pushint 111
divide
callproperty print 1
returnvoid
}
In the following case, the result is converted to an integer, and the entire
division gets folded to the constant '5':
function main():int
{
pushint 555
pushint 111
divide
coerce_i
returnvalue
}
This is apparently being done by folding the double result of the double division of the operands coerced to doubles.
I believe that the only situation in which Tamarin actually generates a LIR_divi is the case of a non-constant integer dividend and a constant, nonzero
divisor.
Assignee | ||
Comment 10•14 years ago
|
||
It would apparently be possible, however, for imm2Int to produce a constant value, so that both arguments would be immediates, which would crash Nanojit. I'm not yet convinced this cannot happen.
Assignee | ||
Comment 11•14 years ago
|
||
Tighten up the logic a bit to protect against any possibility that we give LIR_divi two constant arguments, which will crash Nanojit (assertion, by design).
Rick -- this needs to land in TR ASAP, so I'm asking you to review. Edwin -- if you happen to see this first, feel free to poach the review.
Attachment #520055 -
Flags: review?(rreitmai)
Attachment #520055 -
Flags: feedback?(edwsmith)
Assignee | ||
Comment 12•14 years ago
|
||
Edwin and I agree that this code is less obvious than it should be, and that the lowest risk fix for Wasabi is to rip it out. The optimization is specific to i386 and X64, as no other platforms support LIR_divi in Nanojit.
Attachment #520086 -
Flags: review?(edwsmith)
Updated•14 years ago
|
Attachment #520086 -
Flags: review?(edwsmith) → review+
Assignee | ||
Comment 13•14 years ago
|
||
Pushed to tr-spicy:
http://hg.mozilla.org/users/stejohns_adobe.com/tr-spicy/rev/55ac92ea3533
Assignee | ||
Updated•14 years ago
|
Whiteboard: WE:2831430,has-patch
Comment 14•14 years ago
|
||
I'd be comfortable r+'ing attachment 520004 [details] [diff] [review], but I'll have to examine attachment 520055 [details] [diff] [review] in more detail as there are some subtle changes in the logic.
Updated•14 years ago
|
Flags: in-testsuite?
Flags: flashplayer-qrb+
Assignee | ||
Updated•14 years ago
|
Whiteboard: WE:2831430,has-patch → WE:2831430,has-patch,fixed-in-wasabi
Assignee | ||
Comment 15•14 years ago
|
||
Retargetting for Serrano, as we need to fix the broken optimization that we just removed from Wasabi.
Status: NEW → ASSIGNED
Target Milestone: Q2 11 - Wasabi → Q3 11 - Serrano
Assignee | ||
Comment 16•14 years ago
|
||
Grumble. It looks like the optimization in Spicy landed before the Nanojit support, and NJ_DIVI_SUPPORTED is not defined for any platfom there. As a result, despite the presence of the buggy optimization, as identified and reproduced in TR, Spicy/Wasabi did not actually manifest the bug. Silly me to test the result of the fix, but not verify the original bug in Spicy/Wasabi as well as TR.
I suspect that this is another example of unfortunate timing for creation of the Spicy branch. Most likely, the Nanojit support for LIR_divi was still tied up in review, and the dependent optimization was landed in advance.
Comment 17•14 years ago
|
||
Silver lining: it means the bug hasn't been released into the wild yet, and won't be now.
Updated•14 years ago
|
Attachment #520055 -
Flags: review?(rreitmai) → review+
Assignee | ||
Updated•14 years ago
|
Attachment #520055 -
Flags: feedback?(edwsmith)
Assignee | ||
Comment 18•14 years ago
|
||
Attachment #523143 -
Flags: review?(rreitmai)
Comment 19•14 years ago
|
||
changeset: 6146:5ef0a32feefc
user: William Maddox <wmaddox@adobe.com>
summary: Bug 642535 - Avoid using LIR_divi on unsigned integers. (r=rreitmai)
http://hg.mozilla.org/tamarin-redux/rev/5ef0a32feefc
Assignee | ||
Updated•14 years ago
|
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Whiteboard: WE:2831430,has-patch,fixed-in-wasabi → WE:2831430,has-patch,fixed-in-wasabi,fixed-in-tamarin
Updated•14 years ago
|
Attachment #523143 -
Flags: review?(rreitmai) → review+
You need to log in
before you can comment on or make changes to this bug.
Description
•