[PR,57810] Wasted work in validate_const_int()
diff mbox

Message ID 4978b6a088d027de6688a6baf6f8016d.squirrel@webmail.cs.wisc.edu
State New
Headers show

Commit Message

pchang9@cs.wisc.edu July 17, 2013, 4:41 p.m. UTC
Hi,

The problem appears in revision 200945 in version 4.9.  I attached
a one-line patch that fixes it.  I also reported this problem at
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57810 .

In method "validate_const_int()" in "gcc/read-rtl.c", the loop on line 804
should break immediately after "valid" is set to "0". All the iterations
after "valid" set to "0" do not perform any useful work, at best they just
set "valid" again to "0".

Suggested patch:


-Chang
Index: gcc/read-rtl.c
===================================================================
--- gcc/read-rtl.c	(revision 200945)
+++ gcc/read-rtl.c	(working copy)
@@ -803,7 +803,11 @@
     valid = 0;
   for (; *cp; cp++)
     if (! ISDIGIT (*cp))
-      valid = 0;
+      {
+        valid = 0;
+        break;
+      }
+
   if (!valid)
     fatal_with_file_and_line ("invalid decimal constant \"%s\"\n", string);
 }

Comments

Jeff Law July 17, 2013, 5:03 p.m. UTC | #1
On 07/17/2013 10:41 AM, pchang9@cs.wisc.edu wrote:
> Hi,
>
> The problem appears in revision 200945 in version 4.9.  I attached
> a one-line patch that fixes it.  I also reported this problem at
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57810 .
>
> In method "validate_const_int()" in "gcc/read-rtl.c", the loop on line 804
> should break immediately after "valid" is set to "0". All the iterations
> after "valid" set to "0" do not perform any useful work, at best they just
> set "valid" again to "0".
It may seem a bit of overkill for these patchs, but did you bootstrap 
and/or regression test this or your prior patch?

Our policies require bootstrap and regression tests to help ensure the 
quality of the sourcebase.  I'll go ahead and bootstrap your two changes 
for the sake of completeness (they both look obviously correct to me).

Thanks,
Jeff
Jeff Law July 18, 2013, 4:09 p.m. UTC | #2
On 07/17/2013 10:41 AM, pchang9@cs.wisc.edu wrote:
> Hi,
>
> The problem appears in revision 200945 in version 4.9.  I attached
> a one-line patch that fixes it.  I also reported this problem at
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57810 .
>
> In method "validate_const_int()" in "gcc/read-rtl.c", the loop on line 804
> should break immediately after "valid" is set to "0". All the iterations
> after "valid" set to "0" do not perform any useful work, at best they just
> set "valid" again to "0".

Bootstrapped and regression tested on x86_64-unknown-linux-gnu. 
Installed onto the trunk.

jeff

Patch
diff mbox

Index: gcc/read-rtl.c
===================================================================
--- gcc/read-rtl.c	(revision 200945)
+++ gcc/read-rtl.c	(working copy)
@@ -803,7 +803,11 @@ 
     valid = 0;
   for (; *cp; cp++)
     if (! ISDIGIT (*cp))
-      valid = 0;
+      {
+        valid = 0;
+        break;
+      }
+
   if (!valid)
     fatal_with_file_and_line ("invalid decimal constant \"%s\"\n", string);
 }