public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/115202] [11/12/13/14/15 Regression] Missed optimization: std::min(f ? (unsigned short)m : a, ~0) Date: Thu, 23 May 2024 12:18:41 +0000 [thread overview] Message-ID: <bug-115202-4-kzgA3PVnoH@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-115202-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115202 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|14.2 |11.5 Status|UNCONFIRMED |NEW Last reconfirmed| |2024-05-23 Summary|[14/15 Regression] Missed |[11/12/13/14/15 Regression] |optimization: std::min(f ? |Missed optimization: |(unsigned short)m : a, ~0) |std::min(f ? (unsigned | |short)m : a, ~0) Ever confirmed|0 |1 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Confirmed. Here is a reduced testcase: ``` unsigned short m; template<typename T> const T min(const T a, const T b) { if (a < b) return a; return b; } unsigned short func(int a, int f) { return min(f ? m : a, ~0); } ``` The above is a regression from GCC 8 where in GCC 9 adds an early phiopt. And here is a version which is not a regression: ``` unsigned short m; template<typename T> inline const T min(const T a, const T b) { return a < b ? a : b; } unsigned short func(int a, int f) { return min(f ? m : a, ~0); } ``` The real issue is we don't optimize MIN<PHI<>, -1>. From the IR: ``` # RANGE [irange] int [0, 65535] MASK 0xffff VALUE 0x0 iftmp.0_6 = (intD.9) m.1_1; ;; succ: 4 [always] count:536870912 (estimated locally, freq 0.5000) (FALLTHRU,EXECUTABLE) ;; basic block 4, loop depth 0, count 1073741824 (estimated locally, freq 1.0000), maybe hot ;; prev block 3, next block 1, flags: (NEW, REACHABLE, VISITED) ;; pred: 3 [always] count:536870912 (estimated locally, freq 0.5000) (FALLTHRU,EXECUTABLE) ;; 2 [50.0% (guessed)] count:536870912 (estimated locally, freq 0.5000) (FALSE_VALUE,EXECUTABLE) # iftmp.0_2 = PHI <iftmp.0_6(3), a_4(D)(2)> # RANGE [irange] int [-INF, -1] _7 = MIN_EXPR <iftmp.0_2, -1>; ``` Obviously here `MIN_EXPR <X, -1>` for the iftmp.0_6 part of the PHI, it will be -1.
prev parent reply other threads:[~2024-05-23 12:18 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-05-23 7:44 [Bug tree-optimization/115202] New: [14/15 " 652023330028 at smail dot nju.edu.cn 2024-05-23 9:02 ` [Bug tree-optimization/115202] " rguenth at gcc dot gnu.org 2024-05-23 12:18 ` pinskia at gcc dot gnu.org [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-115202-4-kzgA3PVnoH@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).