public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "kristerw at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114032] New: ifcvt may introduce UB calls to __builtin_clz(0) Date: Wed, 21 Feb 2024 14:03:26 +0000 [thread overview] Message-ID: <bug-114032-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114032 Bug ID: 114032 Summary: ifcvt may introduce UB calls to __builtin_clz(0) Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: kristerw at gcc dot gnu.org Target Milestone: --- The ifcvt pass may make the code more UB, which can be seen by compiling the following function with -O3 for X86_64: int a, b, i; int scaleValueSaturate(int value) { if (value) { int result = __builtin_clz(value); if (-result <= a) return 0; } return b; } short dst; short *src; void scaleValuesSaturate() { for (; i; i++) dst = scaleValueSaturate(src[i]); } What is happening here is that the code for .LOOP_VECTORIZED (1, 2) != 0 always calls __builtin_clz, even when value is 0: <bb 5> [local count: 955630224]: # i.5_21 = PHI <_7(9), i.5_20(24)> _2 = (long unsigned int) i.5_21; _3 = _2 * 2; _4 = src.2_1 + _3; _5 = *_4; value.0_11 = (unsigned int) _5; result_14 = __builtin_clz (value.0_11); _47 = (unsigned int) result_14; _48 = -_47; _15 = (int) _48; _23 = _5 != 0; _28 = _15 <= a.1_16; _46 = _23 & _28; prephitmp_31 = _46 ? 0 : _30; dst = prephitmp_31; _7 = i.5_21 + 1; i = _7; if (_7 != 0) goto <bb 9>; [89.00%] else goto <bb 14>; [11.00%]
next reply other threads:[~2024-02-21 14:03 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-21 14:03 kristerw at gcc dot gnu.org [this message] 2024-02-21 14:37 ` [Bug tree-optimization/114032] " jakub at gcc dot gnu.org 2024-02-22 10:50 ` rguenth at gcc dot gnu.org 2024-02-22 11:03 ` jakub 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-114032-4@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).