From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4457 invoked by alias); 2 Sep 2004 01:39:14 -0000 Mailing-List: contact java-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-prs-owner@gcc.gnu.org Received: (qmail 4362 invoked by uid 48); 2 Sep 2004 01:39:11 -0000 Date: Thu, 02 Sep 2004 01:39:00 -0000 Message-ID: <20040902013911.4361.qmail@sourceware.org> From: "tromey at gcc dot gnu dot org" To: java-prs@gcc.gnu.org In-Reply-To: <20040518204228.15525.tromey@gcc.gnu.org> References: <20040518204228.15525.tromey@gcc.gnu.org> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug java/15525] suggestion to enable cast elimination X-Bugzilla-Reason: CC X-SW-Source: 2004-q3/txt/msg00375.txt.bz2 List-Id: ------- 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; : if (_Jv_IsInstanceOf (x, &q.class) == 0) goto ; else goto ; :; T.2 = 0; goto (); :; T.2 = this->f == _Jv_CheckCast (&q.class, x)->f; :; return T.2; } ;; Function () (_ZN1qC1Ev) () (this) { : (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; : T.3 = _Jv_IsInstanceOf (x, &q.class); if (x == 0B || !T.3) goto ; else goto ; :; T.6 = 0; goto (); :; if (x != 0B) goto ; else goto ; :; iftmp.10 = 0B; goto (); :; if (T.3) goto ; else goto ; :; iftmp.10 = (struct q *) x; goto (); :; _Jv_ThrowCast (&q.class, x); :; :; T.6 = this->f == iftmp.10->f; :; return T.6; } ;; Function () (_ZN1qC1Ev) () (this) { : (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 , and note earlier that T.3 is never 0. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15525