public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/111151] [12/13/14 Regression] Wrong code at -O0 on x86_64-pc-linux-gnu Date: Fri, 25 Aug 2023 12:27:24 +0000 [thread overview] Message-ID: <bug-111151-4-PWJCCFbsqX@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-111151-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111151 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |pinskia at gcc dot gnu.org, | |rguenth at gcc dot gnu.org --- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- instrumenting extract_muldiv shows ... Applying pattern match.pd:5113, generic-match-4.cc:2339 Applying fold-const.c:6892 Applying fold-const.c:7101 Applying fold-const.c:6892 Applying fold-const.c:6985 Applying pattern match.pd:4392, generic-match-8.cc:3091 and commenting case MIN_EXPR: case MAX_EXPR: /* If widening the type changes the signedness, then we can't perform this optimization as that changes the result. */ if (TYPE_UNSIGNED (ctype) != TYPE_UNSIGNED (type)) break; /* MIN (a, b) / 5 -> MIN (a / 5, b / 5) */ sub_strict_overflow_p = false; if ((t1 = extract_muldiv (op0, c, code, wide_type, &sub_strict_overflow_p)) != 0 && (t2 = extract_muldiv (op1, c, code, wide_type, &sub_strict_overflow_p)) != 0) { if (tree_int_cst_sgn (c) < 0) tcode = (tcode == MIN_EXPR ? MAX_EXPR : MIN_EXPR); if (sub_strict_overflow_p) *strict_overflow_p = true; return DUMP_FOLD (fold_build2 (tcode, ctype, fold_convert (ctype, t1), fold_convert (ctype, t2))); } break; fixes the testcase. We turn MAX ((long long unsigned int) t + 4503599, 32739) * 18446744073709551606 to MIN ((long long unsigned int) t * 18446744073709551606 + 18446744073664515626, 18446744073709224226) I think when overflow wraps we cannot do this transform at all, independent on the "sign" of 'c'. Maybe @@ -6970,8 +6972,11 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type, /* MIN (a, b) / 5 -> MIN (a / 5, b / 5) */ sub_strict_overflow_p = false; - if ((t1 = extract_muldiv (op0, c, code, wide_type, - &sub_strict_overflow_p)) != 0 + if ((wide_type + ? TYPE_OVERFLOW_UNDEFINED (wide_type) + : TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (op0))) + && (t1 = extract_muldiv (op0, c, code, wide_type, + &sub_strict_overflow_p)) != 0 && (t2 = extract_muldiv (op1, c, code, wide_type, &sub_strict_overflow_p)) != 0) {
next prev parent reply other threads:[~2023-08-25 12:27 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-08-25 6:39 [Bug middle-end/111151] New: " jwzeng at nuaa dot edu.cn 2023-08-25 7:16 ` [Bug middle-end/111151] " rguenth at gcc dot gnu.org 2023-08-25 7:16 ` rguenth at gcc dot gnu.org 2023-08-25 11:51 ` mikpelinux at gmail dot com 2023-08-25 12:27 ` rguenth at gcc dot gnu.org [this message] 2023-08-25 12:28 ` rguenth at gcc dot gnu.org 2023-08-25 12:35 ` rguenth at gcc dot gnu.org 2023-08-26 3:27 ` pinskia at gcc dot gnu.org 2024-03-22 13:40 ` law at gcc dot gnu.org 2024-03-22 17:29 ` jakub at gcc dot gnu.org 2024-03-22 17:37 ` jakub at gcc dot gnu.org 2024-03-22 17:41 ` jakub at gcc dot gnu.org 2024-03-22 17:57 ` jakub at gcc dot gnu.org 2024-03-22 18:48 ` jakub at gcc dot gnu.org 2024-03-22 19:15 ` jakub at gcc dot gnu.org 2024-03-25 7:23 ` rguenth at gcc dot gnu.org 2024-03-25 11:01 ` jakub at gcc dot gnu.org 2024-03-25 12:45 ` rguenth at gcc dot gnu.org 2024-03-26 10:22 ` cvs-commit at gcc dot gnu.org 2024-03-26 10:32 ` [Bug middle-end/111151] [12/13 " jakub at gcc dot gnu.org 2024-03-26 15:43 ` cvs-commit at gcc dot gnu.org 2024-03-30 3:55 ` cvs-commit at gcc dot gnu.org
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-111151-4-PWJCCFbsqX@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).