From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5D21F3858415; Tue, 28 Nov 2023 22:32:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5D21F3858415 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701210721; bh=El81d0Jf+Dxn0GYOmX/RIx/+rl3Kl8WzQc33LuXvPBg=; h=From:To:Subject:Date:From; b=ooRSRRMwvZTEJFv9QcP/6xhWZAAujSDH+pGD9At3Ev+QdPWHVIZVkXpbNyCVt99BK JaY03/MkDypjhiKMMgjsyuNlRs0FlstS0laxW5goShaEP/sxG1+Rvy1HAZ4KZ8DXmx YiVIU5qCf5ZHunRPgeM/IgHZLW6pRubnNHQ0Nlbk= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/112752] New: `~a - MIN, ~c>` is not optimized to `MAX,c> - a` Date: Tue, 28 Nov 2023 22:32:01 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter cc target_milestone cf_gcctarget Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112752 Bug ID: 112752 Summary: `~a - MIN, ~c>` is not optimized to `MAX,c> - a` Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org CC: evstupac at gmail dot com, kirill.yukhin at intel dot c= om, pinskia at gcc dot gnu.org, rguenth at gcc dot gnu.org, unassigned at gcc dot gnu.org Target Milestone: --- Target: x86_64-*-* +++ This bug was initially created as a clone of Bug #52252 +++ This is an example of byte conversion from RGB (Red Green Blue) to CMYK (Cy= an Magenta Yellow blacK): ``` #define byte unsigned char #define MIN(a, b) ((a) > (b)?(b):(a)) void convert_image(byte *in, byte *out, int size) { int i; for(i =3D 0; i < size; i++) { byte r =3D in[0]; byte g =3D in[1]; byte b =3D in[2]; byte c, m, y, k, tmp; c =3D 255 - r; m =3D 255 - g; y =3D 255 - b; tmp =3D MIN(m, y); k =3D MIN(c, tmp); out[0] =3D c - k; out[1] =3D m - k; out[2] =3D y - k; out[3] =3D k; in +=3D 3; out +=3D 4; } } ``` For the scalar (and vectorized versions) we should get instead: ``` #define byte unsigned char #define MIN(a, b) ((a) > (b)?(b):(a)) #define MAX(a, b) ((a) < (b)?(b):(a)) void convert_image_1(byte *in, byte *out, int size) { int i; for(i =3D 0; i < size; i++) { byte r =3D in[0]; byte g =3D in[1]; byte b =3D in[2]; byte c, m, y, k, tmp; tmp =3D MIN(r, g); k =3D MIN(b, tmp); out[0] =3D k - r; out[1] =3D k - g; out[2] =3D k - b; out[3] =3D 255 - k; in +=3D 3; out +=3D 4; } } ``` See bug 52252 comment #10, 11, and 12 also.=