[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2023-10-16 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

Andrew Pinski  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED
   Target Milestone|--- |14.0

--- Comment #22 from Andrew Pinski  ---
Fixed.

[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2023-10-16 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

--- Comment #21 from CVS Commits  ---
The trunk branch has been updated by Andrew Pinski :

https://gcc.gnu.org/g:29a4453c7b8a86d242dab89b9e4d222749fd911e

commit r14-4661-g29a4453c7b8a86d242dab89b9e4d222749fd911e
Author: Andrew Pinski 
Date:   Sun Oct 15 15:18:42 2023 -0700

[PR31531] MATCH: Improve ~a < ~b and ~a < CST, allow a nop cast inbetween ~
and a/b

Currently we able to simplify `~a CMP ~b` to `b CMP a` but we should allow
a nop
conversion in between the `~` and the `a` which can show up. A similarly
thing should
be done for `~a CMP CST`.

I had originally submitted the `~a CMP CST` case as
https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585088.html;
I noticed we should do the same thing for the `~a CMP ~b` case and combined
it with that one here.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

PR tree-optimization/31531

gcc/ChangeLog:

* match.pd (~X op ~Y): Allow for an optional nop convert.
(~X op C): Likewise.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr31531-1.c: New test.
* gcc.dg/tree-ssa/pr31531-2.c: New test.

[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2023-10-15 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

Andrew Pinski  changed:

   What|Removed |Added

URL|https://gcc.gnu.org/piperma |https://gcc.gnu.org/piperma
   |il/gcc-patches/2021-Novembe |il/gcc-patches/2023-October
   |r/585088.html   |/633090.html

--- Comment #20 from Andrew Pinski  ---
Updated patch:
https://gcc.gnu.org/pipermail/gcc-patches/2023-October/633090.html

[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2023-10-15 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

--- Comment #19 from Andrew Pinski  ---
Created attachment 56119
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56119=edit
testcase from the original attachment

For easier access, I posting this here so don't need to untar the file.

[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2021-11-21 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

Andrew Pinski  changed:

   What|Removed |Added

URL||https://gcc.gnu.org/piperma
   ||il/gcc-patches/2021-Novembe
   ||r/585088.html
   Keywords||patch

--- Comment #18 from Andrew Pinski  ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585088.html

[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2021-11-20 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

Andrew Pinski  changed:

   What|Removed |Added

  Attachment #26645|0   |1
is obsolete||

--- Comment #17 from Andrew Pinski  ---
Created attachment 51841
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51841=edit
Patch which I am testing

Attached patch which I am testing. should resolve this fully.

[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2021-11-19 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

--- Comment #16 from Andrew Pinski  ---
The only patch which is needed now:
diff --git a/gcc/match.pd b/gcc/match.pd
index 37c5be9e5f4..ca6c9eff624 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4729,10 +4729,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 (for cmp (simple_comparison)
  scmp (swapped_simple_comparison)
  (simplify
-  (cmp (bit_not@2 @0) CONSTANT_CLASS_P@1)
+  (cmp (nop_convert?:s (bit_not@2 @0)) CONSTANT_CLASS_P@1)
   (if (single_use (@2)
&& (TREE_CODE (@1) == INTEGER_CST || TREE_CODE (@1) == VECTOR_CST))
-   (scmp @0 (bit_not @1)
+   (with { tree type1 = TREE_TYPE (@1); }
+(scmp (convert:type1 @0) (bit_not @1))

 (for cmp (simple_comparison)
  /* Fold (double)float1 CMP (double)float2 into float1 CMP float2.  */

I will add a testcase and submit it in a few.

[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2021-06-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

Andrew Pinski  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED

--- Comment #15 from Andrew Pinski  ---
(In reply to Andrew Pinski from comment #14)
> My patch needs to be re-written to use match.pd instead.

I am going to update it.

[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2016-01-21 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

Andrew Pinski  changed:

   What|Removed |Added

 Status|ASSIGNED|NEW

--- Comment #14 from Andrew Pinski  ---
My patch needs to be re-written to use match.pd instead.

[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2014-10-30 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531
Bug 31531 depends on bug 15459, which changed state.

Bug 15459 Summary: [meta-bug] there should be a tree combiner like the rtl one
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=15459

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED


[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2012-02-13 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

--- Comment #13 from Andrew Pinski pinskia at gcc dot gnu.org 2012-02-14 
03:59:12 UTC ---
I committed the branch to the git only branch pinskia/treecombine.  The only
regression is gcc.target/i386/umod-3.c.  This is not really a regression but
rather a testcase issue as we produce better code and not produce a division at
all.


[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2012-02-12 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

--- Comment #9 from Andrew Pinski pinskia at gcc dot gnu.org 2012-02-12 
22:58:41 UTC ---
(In reply to comment #8)
 forwprop already handles:
 int f(int a)
 {
   int b = ~a;
   return b0;
 }
 
 It just needs to handle:
 int f(unsigned a)
 {
   int b = ~a;
   return b0;
 }

forward_propagate_into_comparison only handles combing of two SSA_NAMEs, it
could handle dealing with a conversion also.


[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2012-02-12 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

--- Comment #10 from Andrew Pinski pinskia at gcc dot gnu.org 2012-02-13 
00:44:11 UTC ---
I have a patch which adds this optimization to fold.  And a partial patch which
adds some of it to forwprop but that fails because we have to create a temp
variable.


[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2012-02-12 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

--- Comment #11 from Andrew Pinski pinskia at gcc dot gnu.org 2012-02-13 
06:30:29 UTC ---
I have a full patch now which also handles PR 14792 once that folding is
included in fold.


[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2012-02-12 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

--- Comment #12 from Andrew Pinski pinskia at gcc dot gnu.org 2012-02-13 
07:46:45 UTC ---
Created attachment 26645
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=26645
Patch which fixes the problem (well the fold-const.c is really only needed for
the original testcase)

ChangeLog:
* fold-const.c (fold_comparison): Handle ((CAST)~X).
* tree-ssa-forwprop.c (combine_cond_expr_cond): Swap operands so
that fold_binary_loc would not return a non-folded tree.
Don't call canonicalize_cond_expr_cond.
(forward_propagate_into_comparison_1): Also combine casts into the comparisons.
(expand_possible_comparison): New function.
(forward_propagate_into_comparison): Call expand_possible_comparison.
(forward_propagate_into_gimple_cond): Take also a gsi.
Call expand_possible_comparison.
(forward_propagate_into_cond): Call expand_possible_comparison.
(ssa_forward_propagate_and_combine): Update call to
forward_propagate_into_gimple_cond.


[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2012-02-11 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

--- Comment #6 from Andrew Pinski pinskia at gcc dot gnu.org 2012-02-12 
04:35:53 UTC ---
The shortest testcase for the problem function:
int isnegative_optimized_4(unsigned int X) {
   int result; // Y is the conditional expression of if-else.
   if ((~X)  31) result = 0;
   elseresult = 1;
   return result;
}

We need to combine the following gimple:
  D.2293_3 = ~X_2(D);
  D.2294_4 = (int) D.2293_3;
  D.2424_9 = D.2294_4 = 0;


[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2012-02-11 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

Andrew Pinski pinskia at gcc dot gnu.org changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
 AssignedTo|unassigned at gcc dot   |pinskia at gcc dot gnu.org
   |gnu.org |

--- Comment #7 from Andrew Pinski pinskia at gcc dot gnu.org 2012-02-12 
04:37:08 UTC ---
Note:
  D.2424_9 = D.2294_4 = 0;
is the same as:
  D.2424_9 = D.2294_4  0;


[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2012-02-11 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

--- Comment #8 from Andrew Pinski pinskia at gcc dot gnu.org 2012-02-12 
04:39:01 UTC ---
forwprop already handles:
int f(int a)
{
  int b = ~a;
  return b0;
}

It just needs to handle:
int f(unsigned a)
{
  int b = ~a;
  return b0;
}


[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2011-07-18 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31531

Andrew Pinski pinskia at gcc dot gnu.org changed:

   What|Removed |Added

   Keywords||TREE

--- Comment #5 from Andrew Pinski pinskia at gcc dot gnu.org 2011-07-18 
22:46:55 UTC ---
All the functions produce the same assembler output in 4.6.1 on x86.  Only
isnegative_optimized_4 produces a difference on some targets (and a difference
IR coming into expand).


[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2007-04-14 Thread pinskia at gcc dot gnu dot org


--- Comment #4 from pinskia at gcc dot gnu dot org  2007-04-15 06:43 ---
There are a couple of ways of fixing this bug, folding while going out of ssa. 
Doing a tree combined which is PR 15459.  Or the patch which I attached.


-- 

pinskia at gcc dot gnu dot org changed:

   What|Removed |Added

  BugsThisDependsOn||15459
 Status|UNCONFIRMED |NEW
 Ever Confirmed|0   |1
   Last reconfirmed|-00-00 00:00:00 |2007-04-15 06:43:24
   date||


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



[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2007-04-10 Thread pinskia at gcc dot gnu dot org


--- Comment #2 from pinskia at gcc dot gnu dot org  2007-04-10 19:17 ---
What the real issue is that we don't fold !(x = 0) into x  0 before
expanding.


-- 

pinskia at gcc dot gnu dot org changed:

   What|Removed |Added

  Component|c   |middle-end
   Keywords||missed-optimization
Summary|A microoptimization of  |A microoptimization of
   |isnegative or   |isnegative of signed integer
   |greaterthan2millions.   |


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



[Bug middle-end/31531] A microoptimization of isnegative of signed integer

2007-04-10 Thread pinskia at gcc dot gnu dot org


--- Comment #3 from pinskia at gcc dot gnu dot org  2007-04-10 19:20 ---
A quick patch like:
Index: expr.c
===
--- expr.c  (revision 123691)
+++ expr.c  (working copy)
@@ -6828,7 +6828,7 @@
   tree type;
   int unsignedp;
   enum machine_mode mode;
-  enum tree_code code = TREE_CODE (exp);
+  enum tree_code code;
   optab this_optab;
   rtx subtarget, original_target;
   int ignore;
@@ -6840,6 +6840,9 @@
  type)   \
 : (expr))

+  if (TREE_CODE (exp) != COND_EXPR  !GIMPLE_TUPLE_P (exp))
+exp = fold (exp);
+  code = TREE_CODE(exp);
   if (GIMPLE_STMT_P (exp))
 {
   type = void_type_node;



Makes all functions emit the same code.


-- 


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