public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug tree-optimization/103218] New: (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level @ 2021-11-13 1:40 pinskia at gcc dot gnu.org 2021-11-13 1:41 ` [Bug tree-optimization/103218] " pinskia at gcc dot gnu.org ` (6 more replies) 0 siblings, 7 replies; 8+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-11-13 1:40 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103218 Bug ID: 103218 Summary: (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: missed-optimization, TREE Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: int f(signed char a) { signed char t = a < 0; return (unsigned char)(t << 7); } At the gimple level we get: int f(signed char a) { signed char t = a < 0; return (unsigned char)(t << 7); } But combine is able to it: Trying 9 -> 10: 9: {r89:QI=r91:SI#0 0>>0x7;clobber flags:CC;} REG_DEAD r91:SI REG_UNUSED flags:CC 10: {r90:QI=r89:QI<<0x7;clobber flags:CC;} REG_DEAD r89:QI REG_UNUSED flags:CC Successfully matched this instruction: (parallel [ (set (reg:QI 90) (and:QI (subreg:QI (reg:SI 91) 0) (const_int -128 [0xffffffffffffff80]))) (clobber (reg:CC 17 flags)) ]) allowing combination of insns 9 and 10 original costs 4 + 4 = 8 replacement cost 4 deferring deletion of insn with uid = 9. modifying insn i3 10: {r90:QI=r91:SI#0&0xffffffffffffff80;clobber flags:CC;} REG_DEAD r91:SI REG_UNUSED flags:CC deferring rescan insn with uid = 10. If we had wrote the testcase like: int f(signed char a) { return (a < 0) << 7; } GCC does optimize it to: (int) NON_LVALUE_EXPR <a> & 128 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/103218] (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level 2021-11-13 1:40 [Bug tree-optimization/103218] New: (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level pinskia at gcc dot gnu.org @ 2021-11-13 1:41 ` pinskia at gcc dot gnu.org 2021-11-13 1:59 ` pinskia at gcc dot gnu.org ` (5 subsequent siblings) 6 siblings, 0 replies; 8+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-11-13 1:41 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103218 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=103216 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Note I noticed this while looking on PR 103216. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/103218] (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level 2021-11-13 1:40 [Bug tree-optimization/103218] New: (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level pinskia at gcc dot gnu.org 2021-11-13 1:41 ` [Bug tree-optimization/103218] " pinskia at gcc dot gnu.org @ 2021-11-13 1:59 ` pinskia at gcc dot gnu.org 2021-11-13 2:11 ` pinskia at gcc dot gnu.org ` (4 subsequent siblings) 6 siblings, 0 replies; 8+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-11-13 1:59 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103218 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2021-11-13 Status|UNCONFIRMED |ASSIGNED Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Note another testcase: signed char f(signed char a) { if (a < 0) return 1u<<7; return 0; } PHIOPT does convert it to: _4 = a_2(D) < 0; _5 = (signed char) _4; _6 = _5 << 7; But then nothing converts it into: _6 = a_2(D) & 128; Let me see what I can do. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/103218] (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level 2021-11-13 1:40 [Bug tree-optimization/103218] New: (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level pinskia at gcc dot gnu.org 2021-11-13 1:41 ` [Bug tree-optimization/103218] " pinskia at gcc dot gnu.org 2021-11-13 1:59 ` pinskia at gcc dot gnu.org @ 2021-11-13 2:11 ` pinskia at gcc dot gnu.org 2021-11-13 6:47 ` pinskia at gcc dot gnu.org ` (3 subsequent siblings) 6 siblings, 0 replies; 8+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-11-13 2:11 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103218 --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- There is code in fold_ternary_loc which does: /* A < 0 ? <sign bit of A> : 0 is simply (A & <sign bit of A>). */ And this works as fold also does (a<0)<<N into (a<0) ? 1<<N : 0 which is not done in match.pd for reasons. We should just handle ((cast)(a < 0)) << signbit in match.pd. Implementing that. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/103218] (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level 2021-11-13 1:40 [Bug tree-optimization/103218] New: (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level pinskia at gcc dot gnu.org ` (2 preceding siblings ...) 2021-11-13 2:11 ` pinskia at gcc dot gnu.org @ 2021-11-13 6:47 ` pinskia at gcc dot gnu.org 2021-11-13 20:15 ` pinskia at gcc dot gnu.org ` (2 subsequent siblings) 6 siblings, 0 replies; 8+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-11-13 6:47 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103218 --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Created attachment 51782 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51782&action=edit patch in testing Patch in testing. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/103218] (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level 2021-11-13 1:40 [Bug tree-optimization/103218] New: (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level pinskia at gcc dot gnu.org ` (3 preceding siblings ...) 2021-11-13 6:47 ` pinskia at gcc dot gnu.org @ 2021-11-13 20:15 ` pinskia at gcc dot gnu.org 2021-11-16 15:09 ` cvs-commit at gcc dot gnu.org 2021-11-16 15:10 ` pinskia at gcc dot gnu.org 6 siblings, 0 replies; 8+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-11-13 20:15 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103218 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- URL| |https://gcc.gnu.org/piperma | |il/gcc-patches/2021-Novembe | |r/584367.html Keywords| |patch --- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Patch submitted: https://gcc.gnu.org/pipermail/gcc-patches/2021-November/584367.html ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/103218] (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level 2021-11-13 1:40 [Bug tree-optimization/103218] New: (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level pinskia at gcc dot gnu.org ` (4 preceding siblings ...) 2021-11-13 20:15 ` pinskia at gcc dot gnu.org @ 2021-11-16 15:09 ` cvs-commit at gcc dot gnu.org 2021-11-16 15:10 ` pinskia at gcc dot gnu.org 6 siblings, 0 replies; 8+ messages in thread From: cvs-commit at gcc dot gnu.org @ 2021-11-16 15:09 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103218 --- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>: https://gcc.gnu.org/g:11c4a06a6c1a9db0bfdb3ee8509392dd7163709c commit r12-5305-g11c4a06a6c1a9db0bfdb3ee8509392dd7163709c Author: Andrew Pinski <apinski@marvell.com> Date: Sat Nov 13 04:16:55 2021 +0000 tree-optimization: [PR103218] Fold ((type)(a<0)) << SIGNBITOFA into ((type)a) & signbit This folds Fold ((type)(a<0)) << SIGNBITOFA into ((type)a) & signbit inside match.pd. This was already handled in fold-cost by: /* A < 0 ? <sign bit of A> : 0 is simply (A & <sign bit of A>). */ I have not removed as we only simplify "a ? POW2 : 0" at the gimple level to "a << CST1" and fold actually does the reverse of folding "(a<0)<<CST" into "(a<0) ? 1<<CST : 0". OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/103218 gcc/ChangeLog: * match.pd: New pattern for "((type)(a<0)) << SIGNBITOFA". gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr103218-1.c: New test. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/103218] (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level 2021-11-13 1:40 [Bug tree-optimization/103218] New: (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level pinskia at gcc dot gnu.org ` (5 preceding siblings ...) 2021-11-16 15:09 ` cvs-commit at gcc dot gnu.org @ 2021-11-16 15:10 ` pinskia at gcc dot gnu.org 6 siblings, 0 replies; 8+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-11-16 15:10 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103218 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |12.0 Status|ASSIGNED |RESOLVED Resolution|--- |FIXED --- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Fixed. ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-11-16 15:10 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-11-13 1:40 [Bug tree-optimization/103218] New: (a < 0) << signbit is not always optimized to a & signbitmask at the gimple level pinskia at gcc dot gnu.org 2021-11-13 1:41 ` [Bug tree-optimization/103218] " pinskia at gcc dot gnu.org 2021-11-13 1:59 ` pinskia at gcc dot gnu.org 2021-11-13 2:11 ` pinskia at gcc dot gnu.org 2021-11-13 6:47 ` pinskia at gcc dot gnu.org 2021-11-13 20:15 ` pinskia at gcc dot gnu.org 2021-11-16 15:09 ` cvs-commit at gcc dot gnu.org 2021-11-16 15:10 ` pinskia at gcc dot gnu.org
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).