* [gcjx] Patch: FYI: bytecode generation bug
@ 2005-12-19 20:35 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2005-12-19 20:35 UTC (permalink / raw)
To: Java Patch List
I'm checking this in on the gcjx branch.
Mark pointed out a bytecode generation bug. The test case:
public class ifgt
{
public static void t(int i)
{
if (0 > i)
System.out.println("negative");
}
public static void main(String[] args)
{
t(0);
}
}
We were improperly optimizing the 'if'.
Fixed as appended.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* bytecode/generate.cc (handle_comparison): Use flip_if_opcode.
* bytecode/byteutil.hh (flip_if_opcode): New function.
Index: bytecode/generate.cc
===================================================================
--- bytecode/generate.cc (revision 108415)
+++ bytecode/generate.cc (working copy)
@@ -2545,7 +2545,7 @@
if (lhs->constant_p ()
&& jint (intb->convert (lhs->type (), lhs->value ())) == 0)
{
- base = invert_if_opcode (zero_if_opcode (base));
+ base = flip_if_opcode (zero_if_opcode (base));
{
push_expr_target push (this, ON_STACK);
rhs->visit (this);
Index: bytecode/byteutil.hh
===================================================================
--- bytecode/byteutil.hh (revision 108809)
+++ bytecode/byteutil.hh (working copy)
@@ -31,8 +31,8 @@
return java_opcode (op_ifeq + base - op_if_icmpeq);
}
-/// Invert a comparison opcode. For instance, given op_if_cmpge, this
-/// will return op_if_cmplt.
+/// Invert the sense of a comparison opcode. For instance, given
+/// op_if_cmpge, this will return op_if_cmplt.
inline java_opcode
invert_if_opcode (java_opcode base)
{
@@ -43,6 +43,56 @@
return java_opcode ((base & 1) ? base + 1 : base - 1);
}
+/// Flip a comparison opcode. This differs from 'invert' in that it
+/// acts as if the left and right sides of the comparison are also
+/// swapped. So, for op_if_cmpge, it will return op_if_cmple.
+inline java_opcode
+flip_if_opcode (java_opcode base)
+{
+ switch (base)
+ {
+ case op_ifeq:
+ case op_ifne:
+ case op_if_icmpeq:
+ case op_if_icmpne:
+ case op_if_acmpeq:
+ case op_if_acmpne:
+ case op_ifnull:
+ case op_ifnonnull:
+ // Nothing.
+ break;
+ case op_iflt:
+ base = op_ifgt;
+ break;
+ case op_ifge:
+ base = op_ifle;
+ break;
+ case op_ifgt:
+ base = op_iflt;
+ break;
+ case op_ifle:
+ base = op_ifge;
+ break;
+ case op_if_icmplt:
+ base = op_if_icmpgt;
+ break;
+ case op_if_icmpge:
+ base = op_if_icmple;
+ break;
+ case op_if_icmpgt:
+ base = op_if_icmplt;
+ break;
+ case op_if_icmple:
+ base = op_if_icmpge;
+ break;
+
+ default:
+ assert (0);
+ }
+
+ return base;
+}
+
/// Return true if the value is a 'return' bytecode of any kind.
inline bool
return_p (int op)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-12-19 20:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-19 20:35 [gcjx] Patch: FYI: bytecode generation bug Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).