public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "tavianator at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/106952] New: Missed optimization: x < y ? x : y not lowered to minss Date: Thu, 15 Sep 2022 15:30:30 +0000 [thread overview] Message-ID: <bug-106952-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106952 Bug ID: 106952 Summary: Missed optimization: x < y ? x : y not lowered to minss Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: tavianator at gmail dot com Target Milestone: --- Created attachment 53580 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53580&action=edit Assembly from gcc -O3 -S bug.c The following is an implementation of a ray/axis-aligned box intersection test: struct ray { float origin[3]; float dir_inv[3]; }; struct box { float min[3]; float max[3]; }; static inline float min(float x, float y) { return x < y ? x : y; } static inline float max(float x, float y) { return x < y ? x : y; } _Bool intersection(const struct ray *ray, const struct box *box) { float tmin = 0.0, tmax = 1.0 / 0.0; for (int i = 0; i < 3; ++i) { float t1 = (box->min[i] - ray->origin[i]) * ray->dir_inv[i]; float t2 = (box->max[i] - ray->origin[i]) * ray->dir_inv[i]; tmin = min(max(t1, tmin), max(t2, tmin)); tmax = max(min(t1, tmax), min(t2, tmax)); } return tmin < tmax; } However, gcc -O3 doesn't use minss/maxss for every min()/max(). Instead, some of them are lowered to conditional jumps which regresses performance significantly since the branches are unpredictable. Simpler variants like tmin = max(tmin, min(t1, t2)); tmax = min(tmax, max(t1, t2)); get the desired codegen, but that behaves differently if t1 or t2 is NaN. "Bisecting" with godbolt.org, it seems this is an old regression: 4.8.5 was good, but 4.9.0 was bad.
next reply other threads:[~2022-09-15 15:30 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-15 15:30 tavianator at gmail dot com [this message] 2022-09-15 15:42 ` [Bug target/106952] " amonakov at gcc dot gnu.org 2022-09-15 15:54 ` tavianator at gmail dot com 2022-09-17 4:47 ` rguenth at gcc dot gnu.org 2023-07-18 10:39 ` rguenth at gcc dot gnu.org 2023-07-20 8:39 ` rguenth at gcc dot gnu.org 2023-07-21 8:18 ` rguenth 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-106952-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).