This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug java/15525] suggestion to enable cast elimination
- From: "tromey at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 2 Sep 2004 01:39:11 -0000
- Subject: [Bug java/15525] suggestion to enable cast elimination
- References: <20040518204228.15525.tromey@gcc.gnu.org>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From tromey at gcc dot gnu dot org 2004-09-02 01:39 -------
Here's my test case. This is idiomatic Java code,
the cast is checked but the check is completely redundant
and can be eliminated in theory; that's the goal.
I compiled with:
gcj -c -O3 -fdump-tree-all q.java
{
int f;
public boolean equals(Object x)
{
if (! (x instanceof q))
return false;
q v = (q) x;
return f == v.f;
}
}
Before the patch, I seethis in q.java.t60.vars:
;; Function q.equals(java.lang.Object) (_ZN1q6equalsEPN4java4lang6ObjectE)
q.equals(java.lang.Object) (this, x)
{
int T.2;
<bb 0>:
if (_Jv_IsInstanceOf (x, &q.class) == 0) goto <L4>; else goto <L1>;
<L4>:;
T.2 = 0;
goto <bb 2> (<L2>);
<L1>:;
T.2 = this->f == _Jv_CheckCast (&q.class, x)->f;
<L2>:;
return T.2;
}
;; Function () (_ZN1qC1Ev)
() (this)
{
<bb 0>:
<init> (this) [tail call];
return;
}
After the patch, q.java.t63.vars:
;; Function q.equals(java.lang.Object) (_ZN1q6equalsEPN4java4lang6ObjectE)
q.equals(java.lang.Object) (this, x)
{
struct q * iftmp.10;
int T.6;
boolean T.3;
<bb 0>:
T.3 = _Jv_IsInstanceOf (x, &q.class);
if (x == 0B || !T.3) goto <L11>; else goto <L1>;
<L11>:;
T.6 = 0;
goto <bb 7> (<L8>);
<L1>:;
if (x != 0B) goto <L2>; else goto <L12>;
<L12>:;
iftmp.10 = 0B;
goto <bb 6> (<L7>);
<L2>:;
if (T.3) goto <L3>; else goto <L4>;
<L3>:;
iftmp.10 = (struct q *) x;
goto <bb 5> (<L5>);
<L4>:;
_Jv_ThrowCast (&q.class, x);
<L5>:;
<L7>:;
T.6 = this->f == iftmp.10->f;
<L8>:;
return T.6;
}
;; Function () (_ZN1qC1Ev)
() (this)
{
<bb 0>:
<init> (this) [tail call];
return;
}
This is an improvement, since we've eliminated an InstanceOf
(the patch works by breaking CheckCast into explicit InstanceOf +
ThrowCast; you won't see the redundant InstanceOf in the first
dump).
With VRP we could also remove the dead call to ThrowCast.
This call is only reached from <L2>, and note earlier that
T.3 is never 0.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15525