OSDN Git Service

2009-08-18 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / builtins.c
index 025c169..1a9e966 100644 (file)
@@ -8737,15 +8737,18 @@ fold_builtin_pow (location_t loc, tree fndecl, tree arg0, tree arg1, tree type)
            }
        }
 
-      /* Optimize pow(pow(x,y),z) = pow(x,y*z).  */
+      /* Optimize pow(pow(x,y),z) = pow(x,y*z) iff x is nonnegative.  */
       if (fcode == BUILT_IN_POW
          || fcode == BUILT_IN_POWF
          || fcode == BUILT_IN_POWL)
        {
          tree arg00 = CALL_EXPR_ARG (arg0, 0);
-         tree arg01 = CALL_EXPR_ARG (arg0, 1);
-         tree narg1 = fold_build2_loc (loc, MULT_EXPR, type, arg01, arg1);
-         return build_call_expr_loc (loc, fndecl, 2, arg00, narg1);
+         if (tree_expr_nonnegative_p (arg00))
+           {
+             tree arg01 = CALL_EXPR_ARG (arg0, 1);
+             tree narg1 = fold_build2_loc (loc, MULT_EXPR, type, arg01, arg1);
+             return build_call_expr_loc (loc, fndecl, 2, arg00, narg1);
+           }
        }
     }