public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PATCH] Fix PR 31531: A microoptimization of isnegative of signed integer
@ 2016-02-08  8:54 Hurugalawadi, Naveen
  2016-02-08  9:16 ` Senthil Kumar Selvaraj
  0 siblings, 1 reply; 10+ messages in thread
From: Hurugalawadi, Naveen @ 2016-02-08  8:54 UTC (permalink / raw)
  To: gcc-patches; +Cc: Pinski, Andrew

[-- Attachment #1: Type: text/plain, Size: 409 bytes --]

Hi,

Please find attached the patch that performs optimization on unsigned values.

Original fold-const part implemented in match.pd.

Please review the patch and let us know if it's OK?

Regression Tested on X86_64 with no regressions.

Thanks,
Naveen

ChangeLog:
* match.pd (cmp (convert (bit_not @0)) INTEGER_CST@1): New Simplifier.

Testsuite/ChangeLog:
* gcc.dg/pr31531.c : New testcase.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr31531.patch --]
[-- Type: text/x-diff; name="pr31531.patch", Size: 1303 bytes --]

diff --git a/gcc/match.pd b/gcc/match.pd
index 6c8ebd5..42f772b 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1452,6 +1452,17 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        && (TYPE_SIZE (TREE_TYPE (@0)) == TYPE_SIZE (TREE_TYPE (@1))))
    (view_convert @1)))
 
+/* Fold ((CAST)~X) op C as ((CAST)X) op' ~C, where op' is the
+   swapped comparison.  */
+(for cmp (tcc_comparison)
+     scmp (swapped_tcc_comparison)
+ (simplify
+  (cmp (convert (bit_not @0)) INTEGER_CST@1)
+  (if (TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (@0))
+       && TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1)))
+   (with { tree cst = fold_convert (TREE_TYPE (@0), @1); }
+    (scmp @0 (bit_not { cst; }))))))
+
 /* Re-association barriers around constants and other re-association
    barriers can be removed.  */
 (simplify
diff --git a/gcc/testsuite/gcc.dg/pr31531.c b/gcc/testsuite/gcc.dg/pr31531.c
new file mode 100644
index 0000000..d687c91
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr31531.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-gimple" } */
+int isnegative_optimized_4 (unsigned int X)
+{
+  int result;
+  if ((~X) >> 31)
+    result = 0;
+  else
+    result = 1;
+  return result;
+}
+/* { dg-final { scan-tree-dump-times "0 != 0" 1 "gimple" } } */

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

end of thread, other threads:[~2016-04-15 16:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-08  8:54 PATCH] Fix PR 31531: A microoptimization of isnegative of signed integer Hurugalawadi, Naveen
2016-02-08  9:16 ` Senthil Kumar Selvaraj
2016-02-08  9:30   ` Richard Biener
2016-02-16  4:51     ` Hurugalawadi, Naveen
2016-03-03  6:25       ` [PING] [PATCH] " Hurugalawadi, Naveen
2016-03-22  7:11         ` [PING2] " Hurugalawadi, Naveen
2016-04-05  9:12           ` [PING 3] " Hurugalawadi, Naveen
2016-04-06 10:59       ` PATCH] " Richard Biener
2016-04-14  3:12         ` Hurugalawadi, Naveen
2016-04-15 16:43           ` Marc Glisse

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