public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug java/15525] suggestion to enable cast elimination
       [not found] <bug-15525-8172@http.gcc.gnu.org/bugzilla/>
@ 2015-10-20 15:07 ` aph at gcc dot gnu.org
  0 siblings, 0 replies; 7+ messages in thread
From: aph at gcc dot gnu.org @ 2015-10-20 15:07 UTC (permalink / raw)
  To: java-prs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=15525

Andrew Haley <aph at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #6 from Andrew Haley <aph at gcc dot gnu.org> ---
We'll never do this.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug java/15525] suggestion to enable cast elimination
  2004-05-18 20:42 [Bug java/15525] New: " tromey at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2005-03-09  9:04 ` pinskia at gcc dot gnu dot org
@ 2005-05-01  0:57 ` tromey at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: tromey at gcc dot gnu dot org @ 2005-05-01  0:57 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From tromey at gcc dot gnu dot org  2005-05-01 00:57 -------
There are a couple more cases where explicit casts can be eliminated.

Code like this will introduce an unneeded cast:

   Object o = "something";
   String s = (String) o;

Of course this is the simplest possible case; I don't know whether
this occurs in real code or not.


Another case is rearranging an array:

   Object[] array = something();
   array[0] = array[1];

This will generate a call to check whether the array can hold the
object, due to the special role arrays play in the type system;
for example this is valid but throws an exception at runtime:

   String[] sarray = ...;
   Object[] oarray = sarray;
   oarray[0] = new Integer(5);

... because Integer can't be cast to String.
In the first array example, we know that the check can be
eliminated because the rhs of the assignment comes from the
same array.

Currently we emit calls to _Jv_CheckArrayStore for this situation.
While we could inline it (making the type check explicit and allowing
elimination in the style of the other parts of this PR), size of the generated
code might be a concern.

Sometimes the precise type of an array is known, for instance if it
is the result of a 'new'.  In this case it would be nice to be able
to eliminate even more checks.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15525


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug java/15525] suggestion to enable cast elimination
  2004-05-18 20:42 [Bug java/15525] New: " tromey at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2004-09-02  1:39 ` tromey at gcc dot gnu dot org
@ 2005-03-09  9:04 ` pinskia at gcc dot gnu dot org
  2005-05-01  0:57 ` tromey at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-03-09  9:04 UTC (permalink / raw)
  To: java-prs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu dot
                   |                            |org
   Last reconfirmed|2004-11-06 19:02:10         |2005-03-09 04:38:34
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15525


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug java/15525] suggestion to enable cast elimination
  2004-05-18 20:42 [Bug java/15525] New: " tromey at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2004-08-27 20:55 ` tromey at gcc dot gnu dot org
@ 2004-09-02  1:39 ` tromey at gcc dot gnu dot org
  2005-03-09  9:04 ` pinskia at gcc dot gnu dot org
  2005-05-01  0:57 ` tromey at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: tromey at gcc dot gnu dot org @ 2004-09-02  1:39 UTC (permalink / raw)
  To: java-prs


------- 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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug java/15525] suggestion to enable cast elimination
  2004-05-18 20:42 [Bug java/15525] New: " tromey at gcc dot gnu dot org
  2004-05-18 21:08 ` [Bug java/15525] " pinskia at gcc dot gnu dot org
  2004-05-20 19:40 ` dnovillo at gcc dot gnu dot org
@ 2004-08-27 20:55 ` tromey at gcc dot gnu dot org
  2004-09-02  1:39 ` tromey at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: tromey at gcc dot gnu dot org @ 2004-08-27 20:55 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From tromey at gcc dot gnu dot org  2004-08-27 20:55 -------
Another approach is not to call _Jv_CheckCast
but to instead turn that into explicit calls
to _Jv_IsInstanceOf and a call to something to
throw the correct exception.  Then if we mark
_Jv_IsInstanceOf as "pure", the optimizers should
be able to eliminate the redundant call.

I have a patch to do this somewhere, I'll upload
it later.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15525


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug java/15525] suggestion to enable cast elimination
  2004-05-18 20:42 [Bug java/15525] New: " tromey at gcc dot gnu dot org
  2004-05-18 21:08 ` [Bug java/15525] " pinskia at gcc dot gnu dot org
@ 2004-05-20 19:40 ` dnovillo at gcc dot gnu dot org
  2004-08-27 20:55 ` tromey at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2004-05-20 19:40 UTC (permalink / raw)
  To: java-prs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |dnovillo at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15525


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug java/15525] suggestion to enable cast elimination
  2004-05-18 20:42 [Bug java/15525] New: " tromey at gcc dot gnu dot org
@ 2004-05-18 21:08 ` pinskia at gcc dot gnu dot org
  2004-05-20 19:40 ` dnovillo at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-18 21:08 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-18 21:08 -------
Confirmed. Actually we generate the following right now for the code you gave which means we do not 
remove the check at all :(

  T.0 = _Jv_IsInstanceOf (x, &foo.class);
  T.1 = !T.0;
  if (T.1)
    {
      return 0B;
    }
  else
    {

    }
  {
    struct foo * self;

    T.2 = _Jv_CheckCast (&foo.class, x);
    self = T.2;
    return self;
  }

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |missed-optimization
   Last reconfirmed|0000-00-00 00:00:00         |2004-05-18 21:08:20
               date|                            |
            Version|unknown                     |3.5.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15525


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-10-20 15:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-15525-8172@http.gcc.gnu.org/bugzilla/>
2015-10-20 15:07 ` [Bug java/15525] suggestion to enable cast elimination aph at gcc dot gnu.org
2004-05-18 20:42 [Bug java/15525] New: " tromey at gcc dot gnu dot org
2004-05-18 21:08 ` [Bug java/15525] " pinskia at gcc dot gnu dot org
2004-05-20 19:40 ` dnovillo at gcc dot gnu dot org
2004-08-27 20:55 ` tromey at gcc dot gnu dot org
2004-09-02  1:39 ` tromey at gcc dot gnu dot org
2005-03-09  9:04 ` pinskia at gcc dot gnu dot org
2005-05-01  0:57 ` tromey at gcc dot gnu dot org

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).