[{"id":3678221,"web_url":"http://patchwork.ozlabs.org/comment/3678221/","msgid":"<CALvbMcCFQXXX=cfwb7fqPZ5-bF+X7nf7tgQ_xA_kNArBS63V1A@mail.gmail.com>","list_archive_url":null,"date":"2026-04-16T14:50:09","subject":"Re: [PATCH v3] match.pd: right shift compare canonicalization\n [PR124808]","submitter":{"id":91428,"url":"http://patchwork.ozlabs.org/api/people/91428/","name":"Andrew Pinski","email":"andrew.pinski@oss.qualcomm.com"},"content":"On Thu, Apr 16, 2026 at 5:29 AM Daniel Henrique Barboza\n<daniel.barboza@oss.qualcomm.com> wrote:\n>\n> From: Daniel Barboza <daniel.barboza@oss.qualcomm.com>\n>\n> Canonicalize right shift non-equality comparisons with constants by\n> turn them into a comparison with a left shifted constant.  Assuming the\n> generic format:\n>\n> (A >> CST1) CMP CST2\n>\n> For CMP (<, >=) we'll compare A with CST2 left shifted by CST1:\n>\n> - (A >> CST1) < CST2  -> A < (CST2 << CST1)\n> - (A >> CST1) >= CST2 -> A >= (CST2 << CST1)\n>\n> And for CMP (<=, >) we need to IOR the lower CST1 bits from the left\n> shift:\n>\n> - (A >> CST1) <= CST2 -> A <= (CST2 << CST1) | mask\n> - (A >> CST1) > CST2  -> A > (CST2 << CST1) | mask\n>\n> Given that the right hand side changes involves just constants, in the\n> end we'll replace a rshift + cmp with just a cmp.\n>\n> Bootstrapped and regression tested in x86, aarch64 and RISC-V.\n>\n>         PR tree-optimization/124808\n>\n> gcc/ChangeLog:\n>\n>         * match.pd(`(A >> CST1) CMP CST2`): New pattern.\n>\n> gcc/testsuite/ChangeLog:\n>\n>         * gcc.dg/tree-ssa/pr124808-2.c: New test.\n>         * gcc.dg/tree-ssa/pr124808.c: New test.\n> ---\n>\n> Changes from v2:\n> - added \"#if GIMPLE\" and \"single_use\" conditions in the pattern\n> - changed pr124808-2.c to scan 'forwprop1' dump instead of 'gimple'\n> - reverted all changes made in sat-1.c\n> - reverted all changes made in pr104479.c\n> - v2 link: https://gcc.gnu.org/pipermail/gcc-patches/2026-April/713005.html\n>\n>  gcc/match.pd                               | 58 ++++++++++++++++\n>  gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c | 44 ++++++++++++\n>  gcc/testsuite/gcc.dg/tree-ssa/pr124808.c   | 78 ++++++++++++++++++++++\n>  3 files changed, 180 insertions(+)\n>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c\n>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr124808.c\n>\n> diff --git a/gcc/match.pd b/gcc/match.pd\n> index 7b652afb43d..8eece2223f9 100644\n> --- a/gcc/match.pd\n> +++ b/gcc/match.pd\n> @@ -5367,6 +5367,64 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)\n>        @0)))))\n>  #endif\n>\n> +#if GIMPLE\n> +/* PR124808: (A >> CST1) CMP CST2 -> A CMP (CST2 << CST1)\n> +   Canonicalize non-equality comparisons between a right\n> +   shift and a constant, turning it into a comparison\n> +   with a constant that is left shifted.  If we view A as:\n> +\n> +   A: \"|--- CST2 ----|--CST1--|\"\n> +\n> +   A >> CST1 will be equal to CST2 for all A values in the\n> +   range CST2 << CST1 to (CST2 << CST1) | 1s_mask (CST1).\n> +\n> +   Therefore:\n> +   - (A >> CST1) < CST2 -> A < (CST2 << CST1), A must\n> +     be smaller than all values from the range;\n> +   - (A >> CST1) <= CST2 -> A <= (CST2 << CST1) | mask,\n> +     A must be smaller or equal than the range end;\n> +   - (A >> CST1) > CST2 -> A > (CST2 << CST1) | mask,\n> +     A must be greater than all values from the range;\n> +   - (A >> CST1) >= CST2 -> A >= (CST2 << CST1), A must\n> +     be greater or equal than the range start.\n> +\n> +   We're also using \"single_use\" and wrapping around \"if GIMPLE\"\n> +   because (1) this class \"VA1 LSHIFT/RSHIFT VAL2 CMP VAL3\" of\n> +   optimizations tend to match CTZ|CLZ builtin patterns and we\n> +   don't want to trip on them and (2) we will get in the way of\n> +   certain optimizations (see ARM's sat-1.c test) that are done\n> +   using GENERIC due to how forwprop currently works.  */\n> +(for cmp (le lt ge gt)\n> + (simplify\n> +  (cmp (rshift@3 @0 INTEGER_CST@1) INTEGER_CST@2)\n> +  (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))\n> +       && single_use (@3)\n\nI think with this being gimple only we can keep `:s` on the rshift.\nCan you see if that works?\nOtherwise this is ok (for stage 1).\n\nThanks,\nAndrew\n\n> +       && tree_fits_uhwi_p (@1)\n> +       && tree_to_uhwi (@1) < TYPE_PRECISION (TREE_TYPE (@0))\n> +       && tree_int_cst_sgn (@2) >= 0\n> +       /* If @2 is nonzero check if we'll overflow when doing\n> +         @2 << @1 by doing a wi::lshift and checking if the\n> +         result is zero (i.e. overflow).  */\n> +       && (wi::to_wide (@2) == 0\n> +          || !wi::eq_p (wi::lshift (wi::to_wide (@2), wi::to_wide (@1)),\n> +                        wi::zero (TYPE_PRECISION (TREE_TYPE (@2))))))\n> +\n> +   /* No need to set the lower @1 bits of the resulting\n> +      lshift for \"<\" and \">=\" comparisons.  */\n> +   (if (cmp == LT_EXPR || cmp == GE_EXPR)\n> +    (cmp @0 (lshift @2 @1))\n> +\n> +     /* For \"<=\" and \">\" set the lower @1 lshift bits.  */\n> +     (with {\n> +       tree type2 = TREE_TYPE (@2);\n> +       unsigned prec = TYPE_PRECISION (type2);\n> +       unsigned mask_len = TREE_INT_CST_LOW (@1);\n> +       wide_int cst1_mask = wi::mask (mask_len, false, prec);\n> +      }\n> +       (cmp @0 (bit_ior (lshift @2 @1)\n> +                       { wide_int_to_tree (type2, cst1_mask); })))))))\n> +#endif\n> +\n>  /* Rewrite an LROTATE_EXPR by a constant into an\n>     RROTATE_EXPR by a new constant.  */\n>  (simplify\n> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c\n> new file mode 100644\n> index 00000000000..bfab8109ce6\n> --- /dev/null\n> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c\n> @@ -0,0 +1,44 @@\n> +/* { dg-additional-options -O2 } */\n> +/* { dg-additional-options -fdump-tree-forwprop1 } */\n> +\n> +long* SetupPrecalculatedData1 (long* a) {\n> +  long b = 1;\n> +  int i;\n> +  for (i = 0; i < 64; i++) {\n> +    if(i>>3 < 7)\n> +      a[i] += (b<<(i+8));\n> +  }\n> +  return a;\n> +}\n> +\n> +long* SetupPrecalculatedData2 (long* a) {\n> +  long b = 1;\n> +  int i;\n> +  for (i = 0; i <= 64; i++) {\n> +    if(i>>3 < 7)\n> +      a[i] += (b<<(i+8));\n> +  }\n> +  return a;\n> +}\n> +\n> +long* SetupPrecalculatedData3 (long* a) {\n> +  long b = 1;\n> +  int i;\n> +  for (i = 0; i < 64; i++) {\n> +    if(i>>3 > 7)\n> +      a[i] += (b<<(i+8));\n> +  }\n> +  return a;\n> +}\n> +\n> +long* SetupPrecalculatedData4 (long* a) {\n> +  long b = 1;\n> +  int i;\n> +  for (i = 0; i < 64; i++) {\n> +    if(i>>3 >= 7)\n> +      a[i] += (b<<(i+8));\n> +  }\n> +  return a;\n> +}\n> +\n> +/* { dg-final { scan-tree-dump-times \">> 3\" 0 forwprop1 } } */\n> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr124808.c b/gcc/testsuite/gcc.dg/tree-ssa/pr124808.c\n> new file mode 100644\n> index 00000000000..5f3c1f0a8c4\n> --- /dev/null\n> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr124808.c\n> @@ -0,0 +1,78 @@\n> +/* { dg-do run } */\n> +/* { dg-options \"-O2\" } */\n> +\n> +void abort(void);\n> +\n> +/* Macro adapted from builtin-object-size-common.h  */\n> +#define FAIL() \\\n> +  do { \\\n> +    __builtin_printf (\"Failure at line: %d\\n\", __LINE__);      \\\n> +    abort();                                                   \\\n> +  } while (0)\n> +\n> +#define SHIFTVAL 3\n> +#define CMPVAL 1\n> +\n> +long setValue1 (long in)\n> +{\n> +  if (in >> SHIFTVAL < CMPVAL)\n> +    return in += SHIFTVAL;\n> +  return -1;\n> +}\n> +\n> +long setValue2 (long in)\n> +{\n> +  if (in >> SHIFTVAL <= CMPVAL)\n> +    return in += SHIFTVAL;\n> +  return -1;\n> +}\n> +\n> +long setValue3 (long in)\n> +{\n> +  if (in >> SHIFTVAL > CMPVAL)\n> +    return in += SHIFTVAL;\n> +  return -1;\n> +}\n> +\n> +long setValue4 (long in)\n> +{\n> +  if (in >> SHIFTVAL >= CMPVAL)\n> +    return in += SHIFTVAL;\n> +  return -1;\n> +}\n> +\n> +int main (void) {\n> +  /* setValue1: in << 3 < 1;  */\n> +  if (setValue1 (7) != 10)\n> +    FAIL ();\n> +  if (setValue1 (8) != -1)\n> +    FAIL ();\n> +\n> +  /* setValue2: in << 3 <= 1;  */\n> +  if (setValue2 (7) != 10)\n> +    FAIL ();\n> +  if (setValue2 (8) != 11)\n> +    FAIL ();\n> +  if (setValue2 (15) != 18)\n> +    FAIL ();\n> +  if (setValue2 (16) != -1)\n> +    FAIL ();\n> +\n> +  /* setValue3: in << 3 > 1;  */\n> +  if (setValue3 (15) != -1)\n> +    FAIL ();\n> +  if (setValue3 (16) != 19)\n> +    FAIL ();\n> +\n> +  /* setValue4: in << 3 >= 1;  */\n> +  if (setValue4 (7) != -1)\n> +    FAIL ();\n> +  if (setValue4 (8) != 11)\n> +    FAIL ();\n> +  if (setValue4 (15) != 18)\n> +    FAIL ();\n> +  if (setValue4 (16) != 19)\n> +    FAIL ();\n> +\n> +  return 0;\n> +}\n> --\n> 2.43.0\n>","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=fOpc6Hc8;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=hBqPoBsh;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=fOpc6Hc8;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=hBqPoBsh","sourceware.org; dmarc=none (p=none dis=none)\n header.from=oss.qualcomm.com","sourceware.org;\n spf=pass smtp.mailfrom=oss.qualcomm.com","server2.sourceware.org;\n arc=pass smtp.remote-ip=205.220.180.131"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fxLYh5m0wz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 00:51:20 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id D4CD74C318B4\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 14:51:05 +0000 (GMT)","from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com\n [205.220.180.131])\n by sourceware.org (Postfix) with ESMTPS id 88C224BA23FB\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 14:50:25 +0000 (GMT)","from pps.filterd (m0279873.ppops.net [127.0.0.1])\n by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 63GC91Fa1668201\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 14:50:23 GMT","from mail-dl1-f70.google.com (mail-dl1-f70.google.com\n [74.125.82.70])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4djtd91tdx-1\n (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 14:50:23 +0000 (GMT)","by mail-dl1-f70.google.com with SMTP id\n a92af1059eb24-127133794b6so22422231c88.1\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 07:50:23 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org D4CD74C318B4","OpenDKIM Filter v2.11.0 sourceware.org 88C224BA23FB"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 88C224BA23FB","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 88C224BA23FB","ARC-Seal":["i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1776351025; cv=pass;\n b=sA+hNcPBVoaGSQBzZyfoOMTwv+b3lvkpruUBqrJ9H7sVjQYMcBjRsHdMW0Uvhc5ffqablSW3sViyqs0QUjq2GBjTs9QTPGoVxFiLdqfd44ka5e9D4kDfkpkJEdZRgi+1DVRyJsznnMe2ika5pKgzxSZ+4XT3L19/c3Zi2gaUreU=","i=1; a=rsa-sha256; t=1776351022; cv=none;\n d=google.com; s=arc-20240605;\n b=QJZb0zNt8vnH/66RTwzy9EeOuS3OUt0ov6dEQaXP7y06A8FsDCm/4XQioqw8BOl6so\n 9I9eBrlytXs84fcz6EjSZ7VNjaxhl1yOYueiFeUu0OBq9/CxfwM0fMnKwIUfKuWvDnAj\n g0dSWkNFltKsOM0hdwQT1Ajux5RnEu7rrz/Bn5Zd6CDcec6HRdrjBBaUVOSY/BKfA8ps\n iuxZ7CpU5GiHVztbRs+7N26JWFBscszJKD63/is8W/Bv0sCWUupxe5FFJeDbrTtSgWD0\n cYSsGQq37/xpSlih24zXwWqTvAl0vI1d5CJIs/zDWA62okOrU2iulIY0dfacmLk6bRe+\n MM3A=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776351025; c=relaxed/simple;\n bh=UK1VpooyGUhdpcW97lqTWF2gSazFkF2Aw11OMPaLjvU=;\n h=DKIM-Signature:DKIM-Signature:MIME-Version:From:Date:Message-ID:\n Subject:To;\n b=QM6N/uhZVmNMcIE5I+rZY5dvXGvGe+QmVagfweBz9DPiULTIiekI1Pn3cS+kXbvX4eBij8ZRMF61hvZr8uL54hnA7alJFediTEVLKLT36pH1JC9oKxCFQ86J0erK1lvptz29O15uEDaXVzlE9cvW6cdiGSN+I1SZUjGLD9n5108=","i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:dkim-signature;\n bh=XBmlxBS2beIAp6zwVcRATH4m5FBHv3TUnOA3eXunN8Q=;\n fh=6iYHMs1AWdlXsix1dekPdk3naIOb8QIZEI8h8UsuOtQ=;\n b=BkjUDBrFpK+RVoG7rdBl60OFiDCQyzEysdIt/U6gnEYAkcj257i6Bqg+IpUFaSlW1J\n 890Cvh6f4OoSW/KEOC/+SbSUcXQyb2Lwwk5UESDqW5cd8whg854Yqay6eDzgonHCB+ZR\n 1OyPfZZyWFLIQQWU4VRrdvwOAMVmdkZd42JEJlO78Ld8C4mXQiNRGiyfOW8c9aney6R8\n eWQykxKW56C7iObeuSfbfcLLv1pgYE53HH3XcUZ/F/+OiLRcNelc4dsjFjMWgvbQGZmK\n cTNPsTvlYcqIdXuBeMBrpGpKA99V5c6u7if0u4rrg9fbbsgSZMTvRP/uLTMAaWjFo/ZW\n /mvQ==; darn=gcc.gnu.org"],"ARC-Authentication-Results":["i=2; server2.sourceware.org","i=1; mx.google.com; arc=none"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n cc:content-transfer-encoding:content-type:date:from:in-reply-to\n :message-id:mime-version:references:subject:to; s=qcppdkim1; bh=\n XBmlxBS2beIAp6zwVcRATH4m5FBHv3TUnOA3eXunN8Q=; b=fOpc6Hc8K7aVoaP4\n t9OAV25J2bC/jQ6mmMjosNxb9B71BmAo3G2+2RcKz41vNRm2ZbNMck+V17AOFVbE\n VP7uV3CQ0Gs08dMgrNDGHhLqierjEaDBfuro+KDxrQNY2x5Lt19LwNHrJA1yarWQ\n sW/aU3diQzIL/J32wRbrDGnIOPEz0kZQes45R4W6Lgyef8pIDKZ2EJZR4jw1SV6L\n 3ebrWOAYC/mccjicjdh8Ts6RmXR8jPPlp9wIQPxsPpMw2E3y4apLpvocg6KhoXKP\n AWaJYmzdqGePPmYmAwen7hkbPcFU7pdCGV9RycJMerB7IdR788h54/xMARl6AzPq\n kv7TtQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1776351022; x=1776955822; darn=gcc.gnu.org;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:from:to:cc:subject:date\n :message-id:reply-to;\n bh=XBmlxBS2beIAp6zwVcRATH4m5FBHv3TUnOA3eXunN8Q=;\n b=hBqPoBshQWJTDPkYu34Q2bT+7dlLGNmg0tWC69hTQkZDGeKbf0RIxsUQTyTDWUM+5S\n X/5PezDnM3Eh2lxZzgGug1Va47+u1PE1NU6BCL+pqfMiW7tQt/efkCAkNe8BTf7w2/8M\n FB92r2eh+s55GY6e8luG/DKrY3f9HEd0nNx+K9kYM/PQuj5EmwGVIUuzNmumgiTQy/Z7\n uxVuU2aS9q8BtflObPwlVwxI6wW1vCwmU+DkpQF0BPQw/FWu5kXBMAVCWCfuTmzc1+S5\n hM7Mw8PkfwaTig9XlMEKun8f1VXx/F4SVVWi9mnrasY77X2zAsKcq3UQk6SlkbsjeKXp\n RNPA=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776351022; x=1776955822;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=XBmlxBS2beIAp6zwVcRATH4m5FBHv3TUnOA3eXunN8Q=;\n b=JSglt0QAt9voYXeMHjYi+l1OUM+tJJhpD22FRohq2qUtXdYt3rXzn2uD490GJ2yry+\n 44waMw4LxgXkJ11psm4k+tIiFubiCBi6SedXNPwm2sObyXMMd2nRLYxQ+ctw6Tcohp/f\n yZGjDNhV0HdoXOTcq4DHiqk9rUrpSjF1QkRK9ylmdBLDTCz4D8qkjANue+868JZfwB3m\n DSjQr2PR+vyl4aygfuXlKBDOEckjmfamwmd57PLE0Wl9BWrpR8QAqeiosTZfpJsbJIIg\n y4VSqn/PJBZASWVO7jgP+4Qdvqkubw2Z/jSoI+AGO0rEoLNGX7oFx1NEXPH0iyvyVC0P\n nahQ==","X-Gm-Message-State":"AOJu0Yzy0BRLmmcLhmkfcfmtddiupqjh/FU+mGNNZ+I++y2pPrJ9835C\n AJ7Miga6wU1EQkTXO9YKexeA17257ftzGHhDukC2jem9D5Ruu/jh4EuSncS3AtjzE6ebX6+W+vI\n v2WflHLDhYmIH2gg5mwmKztJ8lOI2/+7sKCBaCiEq3dob6vRbXMPo14pkvIJDR8YqsAzugJPBSb\n HG2XIpVPOSWftLpTC3z2kJCyAJNuhqJ060jC8F0RUYD/U=","X-Gm-Gg":"AeBDiesX+FvyPRCtkaA51iTAai4SE95YokThl0rvDVqwpViXkfQSWyBizvnWFtzSyqQ\n ViNTCs2+9G8HbE7Udx9fF2A4JoBJ5pavkMARGkEcEqN2VrZlhdNBaXu1WG0AZOVR0i9ODFUfXaI\n tedAFNAhNijXWgG5lnimhubss3C37Us7r+a//5HA7hUQXpd0m2ZmOcl6S5szX97QHl9J+i0yKRK\n /bZ","X-Received":["by 2002:a05:7022:6896:b0:124:9fd8:4ba9 with SMTP id\n a92af1059eb24-12c34e8a959mr15524053c88.12.1776351022242;\n Thu, 16 Apr 2026 07:50:22 -0700 (PDT)","by 2002:a05:7022:6896:b0:124:9fd8:4ba9 with SMTP id\n a92af1059eb24-12c34e8a959mr15524025c88.12.1776351021583; Thu, 16 Apr 2026\n 07:50:21 -0700 (PDT)"],"MIME-Version":"1.0","References":"<20260416122941.286122-1-daniel.barboza@oss.qualcomm.com>","In-Reply-To":"<20260416122941.286122-1-daniel.barboza@oss.qualcomm.com>","From":"Andrew Pinski <andrew.pinski@oss.qualcomm.com>","Date":"Thu, 16 Apr 2026 07:50:09 -0700","X-Gm-Features":"AQROBzC7xCXi7TBxBcqWrHrScagjdJlmkH5aJIbEegK0jXOmiaOOHoyXrkPxDjs","Message-ID":"\n <CALvbMcCFQXXX=cfwb7fqPZ5-bF+X7nf7tgQ_xA_kNArBS63V1A@mail.gmail.com>","Subject":"Re: [PATCH v3] match.pd: right shift compare canonicalization\n [PR124808]","To":"Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>","Cc":"gcc-patches@gcc.gnu.org, jeffrey.law@oss.qualcomm.com","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDE2MDE0MyBTYWx0ZWRfX5fzWB692GzbQ\n ML9lSZVnqtQ3THxbUeXBboeKMHh52PFfYYCJgV+rHWmZGr2gN6UtVED+G58E+HtbdA+UcZ1w1gW\n zDaDrjk7Cv/aWe/kyvQ3nh52Ag3tJnBOjpdsMSJNU/ihRNEUQCtUBiOWz/U/XYADrjwvmvvsPjw\n 2S4IargSzwD8HjH+Chq75AfYby+mnmAry86L/Lqx+izjDYlix0hMqA8dckTNmZhO5CnLYAaXBCf\n 8JUfFdu7nNE8rRud+Gvx0a5jMBmsNzprtc+f7gakDxzJ0sLa7cXrPcHC91ANLa2J1TlMwocEgof\n VF105yz8qKNRPVigjtgRQyzvwGM9CerwJOLbt9ABWk9NQxq5eieGtUtc6h5P3AiHgCcOmakMiRU\n hFvJ0S6Zg7Zay9XO1RUj6IBXgEq0NnORgjurxvc7XaHpjUYHaIJ//HPJMPtK+W5JcSWDdWrpWQn\n xHZ472LLuNcaGI1gDug==","X-Authority-Analysis":"v=2.4 cv=avuCzyZV c=1 sm=1 tr=0 ts=69e0f72f cx=c_pps\n a=SvEPeNj+VMjHSW//kvnxuw==:117 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10\n a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22\n a=rJkE3RaqiGZ5pbrm-msn:22 a=mDV3o1hIAAAA:8 a=EUspDBNiAAAA:8\n a=8Zh73k8Jfu6vWl9W4AwA:9 a=QEXdDO2ut3YA:10 a=Kq8ClHjjuc5pcCNDwlU0:22","X-Proofpoint-GUID":"2CXw09h6trTdQemmLbJ045tw0_nXj10s","X-Proofpoint-ORIG-GUID":"2CXw09h6trTdQemmLbJ045tw0_nXj10s","X-Proofpoint-Virus-Version":"vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-04-16_03,2026-04-16_02,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n impostorscore=0 phishscore=0 spamscore=0 bulkscore=0 priorityscore=1501\n adultscore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0\n classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0\n reason=mlx scancount=1 engine=8.22.0-2604070000 definitions=main-2604160143","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}},{"id":3678262,"web_url":"http://patchwork.ozlabs.org/comment/3678262/","msgid":"<f87c6c59-8bb8-4c20-a0a9-c33164f8c53a@oss.qualcomm.com>","list_archive_url":null,"date":"2026-04-16T15:41:08","subject":"Re: [PATCH v3] match.pd: right shift compare canonicalization\n [PR124808]","submitter":{"id":92288,"url":"http://patchwork.ozlabs.org/api/people/92288/","name":"Daniel Barboza","email":"daniel.barboza@oss.qualcomm.com"},"content":"On 4/16/2026 11:50 AM, Andrew Pinski wrote:\n> On Thu, Apr 16, 2026 at 5:29 AM Daniel Henrique Barboza\n> <daniel.barboza@oss.qualcomm.com> wrote:\n>>\n>> From: Daniel Barboza <daniel.barboza@oss.qualcomm.com>\n>>\n>> Canonicalize right shift non-equality comparisons with constants by\n>> turn them into a comparison with a left shifted constant.  Assuming the\n>> generic format:\n>>\n>> (A >> CST1) CMP CST2\n>>\n>> For CMP (<, >=) we'll compare A with CST2 left shifted by CST1:\n>>\n>> - (A >> CST1) < CST2  -> A < (CST2 << CST1)\n>> - (A >> CST1) >= CST2 -> A >= (CST2 << CST1)\n>>\n>> And for CMP (<=, >) we need to IOR the lower CST1 bits from the left\n>> shift:\n>>\n>> - (A >> CST1) <= CST2 -> A <= (CST2 << CST1) | mask\n>> - (A >> CST1) > CST2  -> A > (CST2 << CST1) | mask\n>>\n>> Given that the right hand side changes involves just constants, in the\n>> end we'll replace a rshift + cmp with just a cmp.\n>>\n>> Bootstrapped and regression tested in x86, aarch64 and RISC-V.\n>>\n>>          PR tree-optimization/124808\n>>\n>> gcc/ChangeLog:\n>>\n>>          * match.pd(`(A >> CST1) CMP CST2`): New pattern.\n>>\n>> gcc/testsuite/ChangeLog:\n>>\n>>          * gcc.dg/tree-ssa/pr124808-2.c: New test.\n>>          * gcc.dg/tree-ssa/pr124808.c: New test.\n>> ---\n>>\n>> Changes from v2:\n>> - added \"#if GIMPLE\" and \"single_use\" conditions in the pattern\n>> - changed pr124808-2.c to scan 'forwprop1' dump instead of 'gimple'\n>> - reverted all changes made in sat-1.c\n>> - reverted all changes made in pr104479.c\n>> - v2 link: https://gcc.gnu.org/pipermail/gcc-patches/2026-April/713005.html\n>>\n>>   gcc/match.pd                               | 58 ++++++++++++++++\n>>   gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c | 44 ++++++++++++\n>>   gcc/testsuite/gcc.dg/tree-ssa/pr124808.c   | 78 ++++++++++++++++++++++\n>>   3 files changed, 180 insertions(+)\n>>   create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c\n>>   create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr124808.c\n>>\n>> diff --git a/gcc/match.pd b/gcc/match.pd\n>> index 7b652afb43d..8eece2223f9 100644\n>> --- a/gcc/match.pd\n>> +++ b/gcc/match.pd\n>> @@ -5367,6 +5367,64 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)\n>>         @0)))))\n>>   #endif\n>>\n>> +#if GIMPLE\n>> +/* PR124808: (A >> CST1) CMP CST2 -> A CMP (CST2 << CST1)\n>> +   Canonicalize non-equality comparisons between a right\n>> +   shift and a constant, turning it into a comparison\n>> +   with a constant that is left shifted.  If we view A as:\n>> +\n>> +   A: \"|--- CST2 ----|--CST1--|\"\n>> +\n>> +   A >> CST1 will be equal to CST2 for all A values in the\n>> +   range CST2 << CST1 to (CST2 << CST1) | 1s_mask (CST1).\n>> +\n>> +   Therefore:\n>> +   - (A >> CST1) < CST2 -> A < (CST2 << CST1), A must\n>> +     be smaller than all values from the range;\n>> +   - (A >> CST1) <= CST2 -> A <= (CST2 << CST1) | mask,\n>> +     A must be smaller or equal than the range end;\n>> +   - (A >> CST1) > CST2 -> A > (CST2 << CST1) | mask,\n>> +     A must be greater than all values from the range;\n>> +   - (A >> CST1) >= CST2 -> A >= (CST2 << CST1), A must\n>> +     be greater or equal than the range start.\n>> +\n>> +   We're also using \"single_use\" and wrapping around \"if GIMPLE\"\n>> +   because (1) this class \"VA1 LSHIFT/RSHIFT VAL2 CMP VAL3\" of\n>> +   optimizations tend to match CTZ|CLZ builtin patterns and we\n>> +   don't want to trip on them and (2) we will get in the way of\n>> +   certain optimizations (see ARM's sat-1.c test) that are done\n>> +   using GENERIC due to how forwprop currently works.  */\n>> +(for cmp (le lt ge gt)\n>> + (simplify\n>> +  (cmp (rshift@3 @0 INTEGER_CST@1) INTEGER_CST@2)\n>> +  (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))\n>> +       && single_use (@3)\n> \n> I think with this being gimple only we can keep `:s` on the rshift.\n> Can you see if that works?\n\nIt doesn't work unfortunately.  If we change the patch to use :s :\n\n@@ -5396,9 +5396,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)\n     using GENERIC due to how forwprop currently works.  */\n  (for cmp (le lt ge gt)\n   (simplify\n-  (cmp (rshift@3 @0 INTEGER_CST@1) INTEGER_CST@2)\n+  (cmp (rshift:s @0 INTEGER_CST@1) INTEGER_CST@2)\n    (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))\n-       && single_use (@3)\n         && tree_fits_uhwi_p (@1)\n         && tree_to_uhwi (@1) < TYPE_PRECISION (TREE_TYPE (@0))\n         && tree_int_cst_sgn (@2) >= 0\n\n\nThe 'optimized' dump from sat-1.c won't emit MIN_EXPR and MAX_EXPR.  E.g.\nfor 'ss2':\n\nintD.7 ss2D.4609 (intD.7 xD.4608)\n{\n   intD.7 x_2(D) = xD.4608;\n   intD.7 _1;\n   intD.7 _4;\n   intD.7 _5;\n\n;;   basic block 2, loop depth 0, count 1073741824 (estimated locally, freq 1.0000), maybe hot\n;;    prev block 0, next block 3, flags: (NEW, REACHABLE, VISITED)\n;;    pred:       ENTRY [always]  count:1073741824 (estimated locally, freq 1.0000) (FALLTHRU,EXECUTABLE)\n   if (x_2(D) > 2047)\n     goto <bb 4>; [34.00%]\n   else\n     goto <bb 3>; [66.00%]\n;;    succ:       4 [34.0% (guessed)]  count:365072224 (estimated locally, freq 0.3400) (TRUE_VALUE,EXECUTABLE)\n;;                3 [66.0% (guessed)]  count:708669600 (estimated locally, freq 0.6600) (FALSE_VALUE,EXECUTABLE)\n\n;;   basic block 3, loop depth 0, count 708669600 (estimated locally, freq 0.6600), maybe hot\n;;    prev block 2, next block 4, flags: (NEW, REACHABLE, VISITED)\n;;    pred:       2 [66.0% (guessed)]  count:708669600 (estimated locally, freq 0.6600) (FALSE_VALUE,EXECUTABLE)\n   # RANGE [irange] int [-67108864, 63]\n   _1 = x_2(D) >> 5;\n   # RANGE [irange] int [-64, 63]\n   _4 = MAX_EXPR <_1, -64>;\n;;    succ:       4 [always]  count:708669600 (estimated locally, freq 0.6600) (FALLTHRU,EXECUTABLE)\n\n;;   basic block 4, loop depth 0, count 1073741824 (estimated locally, freq 1.0000), maybe hot\n;;    prev block 3, next block 1, flags: (NEW, REACHABLE, VISITED)\n;;    pred:       2 [34.0% (guessed)]  count:365072224 (estimated locally, freq 0.3400) (TRUE_VALUE,EXECUTABLE)\n;;                3 [always]  count:708669600 (estimated locally, freq 0.6600) (FALLTHRU,EXECUTABLE)\n   # RANGE [irange] int [-64, 63]\n   # _5 = PHI <63(2), _4(3)>\n   # VUSE <.MEM_3(D)>\n   return _5;\n;;    succ:       EXIT [always]  count:1073741824 (estimated locally, freq 1.0000) (EXECUTABLE) test_sat.c:32:10\n\n}\n\n\nWith the patch as is, same 'ss2' function:\n\nintD.7 ss2D.4609 (intD.7 xD.4608)\n{\n   intD.7 x_2(D) = xD.4608;\n   intD.7 _1;\n   intD.7 _4;\n   intD.7 _5;\n\n;;   basic block 2, loop depth 0, count 1073741824 (estimated locally, freq 1.0000), maybe hot\n;;    prev block 0, next block 1, flags: (NEW, REACHABLE, VISITED)\n;;    pred:       ENTRY [always]  count:1073741824 (estimated locally, freq 1.0000) (FALLTHRU,EXECUTABLE)\n   # RANGE [irange] int [-67108864, 67108863]\n   _1 = x_2(D) >> 5;\n   # RANGE [irange] int [-64, 67108863]\n   _4 = MAX_EXPR <_1, -64>;\n   # RANGE [irange] int [-64, 63]\n   _5 = MIN_EXPR <_4, 63>;\n   # VUSE <.MEM_3(D)>\n   return _5;\n;;    succ:       EXIT [always]  count:1073741824 (estimated locally, freq 1.0000) (EXECUTABLE) test_sat.c:32:10\n\n}\n\n\nNot sure why but seems that we need both \"#if GIMPLE\" and the explicit\nsingle_use() check. Thanks,\n\nDaniel\n\n\n\n\n\n> Otherwise this is ok (for stage 1).\n> \n> Thanks,\n> Andrew\n> \n>> +       && tree_fits_uhwi_p (@1)\n>> +       && tree_to_uhwi (@1) < TYPE_PRECISION (TREE_TYPE (@0))\n>> +       && tree_int_cst_sgn (@2) >= 0\n>> +       /* If @2 is nonzero check if we'll overflow when doing\n>> +         @2 << @1 by doing a wi::lshift and checking if the\n>> +         result is zero (i.e. overflow).  */\n>> +       && (wi::to_wide (@2) == 0\n>> +          || !wi::eq_p (wi::lshift (wi::to_wide (@2), wi::to_wide (@1)),\n>> +                        wi::zero (TYPE_PRECISION (TREE_TYPE (@2))))))\n>> +\n>> +   /* No need to set the lower @1 bits of the resulting\n>> +      lshift for \"<\" and \">=\" comparisons.  */\n>> +   (if (cmp == LT_EXPR || cmp == GE_EXPR)\n>> +    (cmp @0 (lshift @2 @1))\n>> +\n>> +     /* For \"<=\" and \">\" set the lower @1 lshift bits.  */\n>> +     (with {\n>> +       tree type2 = TREE_TYPE (@2);\n>> +       unsigned prec = TYPE_PRECISION (type2);\n>> +       unsigned mask_len = TREE_INT_CST_LOW (@1);\n>> +       wide_int cst1_mask = wi::mask (mask_len, false, prec);\n>> +      }\n>> +       (cmp @0 (bit_ior (lshift @2 @1)\n>> +                       { wide_int_to_tree (type2, cst1_mask); })))))))\n>> +#endif\n>> +\n>>   /* Rewrite an LROTATE_EXPR by a constant into an\n>>      RROTATE_EXPR by a new constant.  */\n>>   (simplify\n>> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c\n>> new file mode 100644\n>> index 00000000000..bfab8109ce6\n>> --- /dev/null\n>> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c\n>> @@ -0,0 +1,44 @@\n>> +/* { dg-additional-options -O2 } */\n>> +/* { dg-additional-options -fdump-tree-forwprop1 } */\n>> +\n>> +long* SetupPrecalculatedData1 (long* a) {\n>> +  long b = 1;\n>> +  int i;\n>> +  for (i = 0; i < 64; i++) {\n>> +    if(i>>3 < 7)\n>> +      a[i] += (b<<(i+8));\n>> +  }\n>> +  return a;\n>> +}\n>> +\n>> +long* SetupPrecalculatedData2 (long* a) {\n>> +  long b = 1;\n>> +  int i;\n>> +  for (i = 0; i <= 64; i++) {\n>> +    if(i>>3 < 7)\n>> +      a[i] += (b<<(i+8));\n>> +  }\n>> +  return a;\n>> +}\n>> +\n>> +long* SetupPrecalculatedData3 (long* a) {\n>> +  long b = 1;\n>> +  int i;\n>> +  for (i = 0; i < 64; i++) {\n>> +    if(i>>3 > 7)\n>> +      a[i] += (b<<(i+8));\n>> +  }\n>> +  return a;\n>> +}\n>> +\n>> +long* SetupPrecalculatedData4 (long* a) {\n>> +  long b = 1;\n>> +  int i;\n>> +  for (i = 0; i < 64; i++) {\n>> +    if(i>>3 >= 7)\n>> +      a[i] += (b<<(i+8));\n>> +  }\n>> +  return a;\n>> +}\n>> +\n>> +/* { dg-final { scan-tree-dump-times \">> 3\" 0 forwprop1 } } */\n>> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr124808.c b/gcc/testsuite/gcc.dg/tree-ssa/pr124808.c\n>> new file mode 100644\n>> index 00000000000..5f3c1f0a8c4\n>> --- /dev/null\n>> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr124808.c\n>> @@ -0,0 +1,78 @@\n>> +/* { dg-do run } */\n>> +/* { dg-options \"-O2\" } */\n>> +\n>> +void abort(void);\n>> +\n>> +/* Macro adapted from builtin-object-size-common.h  */\n>> +#define FAIL() \\\n>> +  do { \\\n>> +    __builtin_printf (\"Failure at line: %d\\n\", __LINE__);      \\\n>> +    abort();                                                   \\\n>> +  } while (0)\n>> +\n>> +#define SHIFTVAL 3\n>> +#define CMPVAL 1\n>> +\n>> +long setValue1 (long in)\n>> +{\n>> +  if (in >> SHIFTVAL < CMPVAL)\n>> +    return in += SHIFTVAL;\n>> +  return -1;\n>> +}\n>> +\n>> +long setValue2 (long in)\n>> +{\n>> +  if (in >> SHIFTVAL <= CMPVAL)\n>> +    return in += SHIFTVAL;\n>> +  return -1;\n>> +}\n>> +\n>> +long setValue3 (long in)\n>> +{\n>> +  if (in >> SHIFTVAL > CMPVAL)\n>> +    return in += SHIFTVAL;\n>> +  return -1;\n>> +}\n>> +\n>> +long setValue4 (long in)\n>> +{\n>> +  if (in >> SHIFTVAL >= CMPVAL)\n>> +    return in += SHIFTVAL;\n>> +  return -1;\n>> +}\n>> +\n>> +int main (void) {\n>> +  /* setValue1: in << 3 < 1;  */\n>> +  if (setValue1 (7) != 10)\n>> +    FAIL ();\n>> +  if (setValue1 (8) != -1)\n>> +    FAIL ();\n>> +\n>> +  /* setValue2: in << 3 <= 1;  */\n>> +  if (setValue2 (7) != 10)\n>> +    FAIL ();\n>> +  if (setValue2 (8) != 11)\n>> +    FAIL ();\n>> +  if (setValue2 (15) != 18)\n>> +    FAIL ();\n>> +  if (setValue2 (16) != -1)\n>> +    FAIL ();\n>> +\n>> +  /* setValue3: in << 3 > 1;  */\n>> +  if (setValue3 (15) != -1)\n>> +    FAIL ();\n>> +  if (setValue3 (16) != 19)\n>> +    FAIL ();\n>> +\n>> +  /* setValue4: in << 3 >= 1;  */\n>> +  if (setValue4 (7) != -1)\n>> +    FAIL ();\n>> +  if (setValue4 (8) != 11)\n>> +    FAIL ();\n>> +  if (setValue4 (15) != 18)\n>> +    FAIL ();\n>> +  if (setValue4 (16) != 19)\n>> +    FAIL ();\n>> +\n>> +  return 0;\n>> +}\n>> --\n>> 2.43.0\n>>","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=flDkPF78;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=kd2qOvR5;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=flDkPF78;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=kd2qOvR5","sourceware.org; dmarc=none (p=none dis=none)\n header.from=oss.qualcomm.com","sourceware.org;\n spf=pass smtp.mailfrom=oss.qualcomm.com","server2.sourceware.org;\n arc=none smtp.remote-ip=205.220.180.131"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fxMgv1wVcz1yHP\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 01:41:47 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 6E40F4BA23FB\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 15:41:45 +0000 (GMT)","from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com\n [205.220.180.131])\n by sourceware.org (Postfix) with ESMTPS id ADDFA4BA23F5\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 15:41:14 +0000 (GMT)","from pps.filterd (m0279873.ppops.net [127.0.0.1])\n by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 63GBhklt1668278\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 15:41:14 GMT","from mail-qk1-f200.google.com (mail-qk1-f200.google.com\n [209.85.222.200])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4djtd920bk-1\n (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 15:41:13 +0000 (GMT)","by mail-qk1-f200.google.com with SMTP id\n af79cd13be357-8d3e4c19307so1261968785a.1\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 08:41:13 -0700 (PDT)","from [192.168.68.106] ([191.202.238.222])\n by smtp.gmail.com with ESMTPSA id\n af79cd13be357-8e4ef817b56sm389607285a.21.2026.04.16.08.41.10\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Thu, 16 Apr 2026 08:41:11 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 6E40F4BA23FB","OpenDKIM Filter v2.11.0 sourceware.org ADDFA4BA23F5"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org ADDFA4BA23F5","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org ADDFA4BA23F5","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776354074; cv=none;\n b=pg4ts4qglVY+vYfeOre6ZVR9rHzn9+Ucci/D25WnjVGV6bIHd5LYnZgeDRiP4CdxvLRaT3fgnuTzNje/d8Jx0STbfqDIKy00sEnYigjhD3KMg2pZ6PId8uEymVrPfWGOjd+WKzFyH4AHaBMmXyIPJf+VrvvrcFEOPll9CAgU/iA=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776354074; c=relaxed/simple;\n bh=Yoa0+t7DZh9MTGUANkjCYT6YCguO1aAckZznCIt7H9s=;\n h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version:\n Subject:To:From;\n b=CqYwIKM4I4aZlGQYQUrrUxqNVCtjR0+aQfRPknH9Y7AbjYyuBWT1v/jqLrCuppUQRUoirxStdA36N1F6wgR08AKxyDRr9Bf5ZtKnrsIzgjW6o/UeI+mEVaflelXjUPbqg780T4pvSfuA36FbJHmMYXdBL5wDkFqkL2vM/0SDUwo=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n cc:content-transfer-encoding:content-type:date:from:in-reply-to\n :message-id:mime-version:references:subject:to; s=qcppdkim1; bh=\n ZxUWr3/pbASgDATp0xu/Z2kivti/0mUf+P3AlfLpQNk=; b=flDkPF78MLEZdn9M\n saoRwvE5UroMZosGu9Vs0S1Fga8KJWU93q38BQx4f+naZ9DAC80hyswfsHYMEsGG\n zNpBigia6ZnXDFGhQ4orZsxgvi4mcGiDbc5d/44IjtFw1MpQez3CbLb4hbJNATgi\n A9GQ7YYG7BaSkPTlndeHf1NHvzaaQ9ywh/ofXY5Cp6CzE+bWKaibc+qstwkt3fnU\n MedSYCYQbebLe6H1Vqs58g7Vmo7SpThZlDLSJwEjwxzN3n6/lveQpxH43bkuQNQO\n +rGPrvlwLxAtGpjzkE1sCzvokxu4RB9to65Wc/L1+Hci9qAh6y9ds7fkAsfWxfzC\n 0eXROg==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1776354073; x=1776958873; darn=gcc.gnu.org;\n h=content-transfer-encoding:in-reply-to:content-language:from\n :references:cc:to:subject:user-agent:mime-version:date:message-id\n :from:to:cc:subject:date:message-id:reply-to;\n bh=ZxUWr3/pbASgDATp0xu/Z2kivti/0mUf+P3AlfLpQNk=;\n b=kd2qOvR5jkNOGDuIr8FEkYHCPuSbjG8tj0m8XBjUnTNbSPnwpxxyW/gbKtGRHZOEoG\n K2VtSUVsMebsq+nFQkvJmegEIP1RY7YeskKc1uRgVM92wAKwQfEXQ16gSK5ySaYTBvBa\n zbPY6a+GDxT8a4DN5+YhOM40Wjn0UYBPdizWHg3ojHdA7J+mgW+/sSiWS4Qvc0ZuP7KE\n LCuRWfOFzm6StoogXWruGFHNyueodcQR1+U7Kikhjg4WWcm4ZzTXgyw9IAQcb5yafHjK\n Ee4YusrlOMtmzfUe/XRdlwQR3Yilc9sFj/g889wXER4ZIlJv+wY4CVCwX3HHiIz3uVac\n SSGw=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776354073; x=1776958873;\n h=content-transfer-encoding:in-reply-to:content-language:from\n :references:cc:to:subject:user-agent:mime-version:date:message-id\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=ZxUWr3/pbASgDATp0xu/Z2kivti/0mUf+P3AlfLpQNk=;\n b=os90PefCM5yQhJK+K/SlTmAkBNfQI3XDL2FJ9fsr6+R3cEZp6No5T9+9fVmYC6jg9N\n IqqxloS7aeyy+0E3Dp6M1JaSe/3Jf88FIc2g2dGSrEnQlw1P3Q0keENx5xF8OiGIrXmo\n 14h2jFEVKbE0i1/9hMZn0t7rPPQDX6zcafp0Th7bWTVFAbJlGzxCEPcTL2Iy6VHKY8Xg\n l/cDCkSIHJ/Jq2bRlG3euIY5Qcp6peH/pTUwTa3R4TgtcxDHXhuusmFabpdfVmmx9XMr\n mED0KFHcow9e2mBIKp1Q+P9WCNpEP9G7mWU8T+DaTuZC3Di9iP4NyxJYYuj58OCo4bSH\n 2TfQ==","X-Gm-Message-State":"AOJu0Yy4Lwmr4VZnquvK8fKhx3AATKgmrnG9sK0G0z1ZaZHwz6fqo+Vc\n m4ajW4KCYlFub+CexWDBW0fy8ibY7NUqIV0WmQdeJ00pHQS1BuJi9QkFDUI1QrULz93LxqiKNYZ\n pVb0Gj6hZRANOgJlRrgbtBGDhPUNN7R5WENt9tdUeddQyieybCx0Vj7mn0vckBUNeer5l","X-Gm-Gg":"AeBDieuf+2ulYoqsG6uk5k1igzRK5rK8t1pLABGLv32LPHqqW0whs12+pcir38FfF7p\n IS9k0z1o39ysbkEcc/LPyd5mGQcZgee8dBid21OHUplkPnb8ZckMVmWWkAqMJhME94bX2GdOahh\n rNak7RpATBBjOPiGcQJfID2+j60yYUU155D2JVp3KAWFDB7dIRmUEu032sqrXWnqxB4r8kv7t9d\n P9p0+SqZcM2QUgogv3fqlaGM53cdPZy82ZVaqRQT5UPyEjlY01R40i9WYSJL9C9z/TNsQKlUaS/\n jkiNLIrD4MXYtyXXiesRbAbrVUz5kMBFdR5kWzGua9HSOlH9F4ldzt5Q5yGleDe1MTvW71QX3md\n YqNPaceqGR51iRJCw/L2ekR6p02QqFyEqJ8hs1Kv9QypaCu2X77kDFVMRE5mkajcQl2laxQ==","X-Received":["by 2002:a05:620a:3e82:b0:8e3:5bd3:c8ac with SMTP id\n af79cd13be357-8e35bd3d0c8mr1203623485a.34.1776354072479;\n Thu, 16 Apr 2026 08:41:12 -0700 (PDT)","by 2002:a05:620a:3e82:b0:8e3:5bd3:c8ac with SMTP id\n af79cd13be357-8e35bd3d0c8mr1203618585a.34.1776354071905;\n Thu, 16 Apr 2026 08:41:11 -0700 (PDT)"],"Message-ID":"<f87c6c59-8bb8-4c20-a0a9-c33164f8c53a@oss.qualcomm.com>","Date":"Thu, 16 Apr 2026 12:41:08 -0300","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3] match.pd: right shift compare canonicalization\n [PR124808]","To":"Andrew Pinski <andrew.pinski@oss.qualcomm.com>","Cc":"gcc-patches@gcc.gnu.org, jeffrey.law@oss.qualcomm.com","References":"<20260416122941.286122-1-daniel.barboza@oss.qualcomm.com>\n <CALvbMcCFQXXX=cfwb7fqPZ5-bF+X7nf7tgQ_xA_kNArBS63V1A@mail.gmail.com>","From":"Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>","Content-Language":"en-US","In-Reply-To":"\n <CALvbMcCFQXXX=cfwb7fqPZ5-bF+X7nf7tgQ_xA_kNArBS63V1A@mail.gmail.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDE2MDE0OSBTYWx0ZWRfXxMD0sEdDv76l\n acGUn1OModE4xxQBSZiloQiGJj/LudyHd+4769chpWbA5PGLByK6PjImYB2eJ/vd7tnm2b0YK1u\n qEjE4RsaM0gHJOL5tx3zJ1djaDeHKDokEA6MW5XJUAMvZhHzz1JONfYdnYHvo0MZPkYB98V2N8b\n QkTz1uwaSCznc6IwiYAMagfWbovSGazT8OZppqaU6syfff7otxauQACvQMIuvjt1+F2eG/PzG50\n /YNH1CPk/aQ7vxq5IC21iMtn1qEgazBmprxeWZwxShlfMfRbmMqUcgT586C7YpNsRjOeHk7Fd34\n 95TjW3zs2SsrJBXNdzxQMe0Fd18aTL/Qmv+tJN5rJB2CDHl+pbkdm0O1hRMiqWfIZ7/rXggnohX\n jGAxCb/g6pYh+z30Spg5VjgCuguLC1keBTLaBCIhpaKmA3P06/rBGWMImhDXgN/vhQhFdBwH29q\n bgWR9iS4/H/qEmn9rEQ==","X-Authority-Analysis":"v=2.4 cv=avuCzyZV c=1 sm=1 tr=0 ts=69e10319 cx=c_pps\n a=hnmNkyzTK/kJ09Xio7VxxA==:117 a=etEqFfc6qwXwpI8uT8rzbw==:17\n a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10\n a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22\n a=mDV3o1hIAAAA:8 a=EUspDBNiAAAA:8 a=IeacuLAUOsDr8Ktl8sMA:9 a=3ZKOabzyN94A:10\n a=QEXdDO2ut3YA:10 a=PEH46H7Ffwr30OY-TuGO:22","X-Proofpoint-GUID":"Gj_0QetBHoZZg1FopIWxeA4VUaKbpv6N","X-Proofpoint-ORIG-GUID":"Gj_0QetBHoZZg1FopIWxeA4VUaKbpv6N","X-Proofpoint-Virus-Version":"vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-04-16_03,2026-04-16_03,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n impostorscore=0 phishscore=0 spamscore=0 bulkscore=0 priorityscore=1501\n adultscore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0\n classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0\n reason=mlx scancount=1 engine=8.22.0-2604070000 definitions=main-2604160149","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}},{"id":3678298,"web_url":"http://patchwork.ozlabs.org/comment/3678298/","msgid":"<CALvbMcCXupBJsbH65c37J6t1c2RGdKr6+fz=kZfN+bQtnrs6XQ@mail.gmail.com>","list_archive_url":null,"date":"2026-04-16T17:45:39","subject":"Re: [PATCH v3] match.pd: right shift compare canonicalization\n [PR124808]","submitter":{"id":91428,"url":"http://patchwork.ozlabs.org/api/people/91428/","name":"Andrew Pinski","email":"andrew.pinski@oss.qualcomm.com"},"content":"On Thu, Apr 16, 2026 at 8:41 AM Daniel Henrique Barboza\n<daniel.barboza@oss.qualcomm.com> wrote:\n>\n>\n>\n> On 4/16/2026 11:50 AM, Andrew Pinski wrote:\n> > On Thu, Apr 16, 2026 at 5:29 AM Daniel Henrique Barboza\n> > <daniel.barboza@oss.qualcomm.com> wrote:\n> >>\n> >> From: Daniel Barboza <daniel.barboza@oss.qualcomm.com>\n> >>\n> >> Canonicalize right shift non-equality comparisons with constants by\n> >> turn them into a comparison with a left shifted constant.  Assuming the\n> >> generic format:\n> >>\n> >> (A >> CST1) CMP CST2\n> >>\n> >> For CMP (<, >=) we'll compare A with CST2 left shifted by CST1:\n> >>\n> >> - (A >> CST1) < CST2  -> A < (CST2 << CST1)\n> >> - (A >> CST1) >= CST2 -> A >= (CST2 << CST1)\n> >>\n> >> And for CMP (<=, >) we need to IOR the lower CST1 bits from the left\n> >> shift:\n> >>\n> >> - (A >> CST1) <= CST2 -> A <= (CST2 << CST1) | mask\n> >> - (A >> CST1) > CST2  -> A > (CST2 << CST1) | mask\n> >>\n> >> Given that the right hand side changes involves just constants, in the\n> >> end we'll replace a rshift + cmp with just a cmp.\n> >>\n> >> Bootstrapped and regression tested in x86, aarch64 and RISC-V.\n> >>\n> >>          PR tree-optimization/124808\n> >>\n> >> gcc/ChangeLog:\n> >>\n> >>          * match.pd(`(A >> CST1) CMP CST2`): New pattern.\n> >>\n> >> gcc/testsuite/ChangeLog:\n> >>\n> >>          * gcc.dg/tree-ssa/pr124808-2.c: New test.\n> >>          * gcc.dg/tree-ssa/pr124808.c: New test.\n> >> ---\n> >>\n> >> Changes from v2:\n> >> - added \"#if GIMPLE\" and \"single_use\" conditions in the pattern\n> >> - changed pr124808-2.c to scan 'forwprop1' dump instead of 'gimple'\n> >> - reverted all changes made in sat-1.c\n> >> - reverted all changes made in pr104479.c\n> >> - v2 link: https://gcc.gnu.org/pipermail/gcc-patches/2026-April/713005.html\n> >>\n> >>   gcc/match.pd                               | 58 ++++++++++++++++\n> >>   gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c | 44 ++++++++++++\n> >>   gcc/testsuite/gcc.dg/tree-ssa/pr124808.c   | 78 ++++++++++++++++++++++\n> >>   3 files changed, 180 insertions(+)\n> >>   create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c\n> >>   create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr124808.c\n> >>\n> >> diff --git a/gcc/match.pd b/gcc/match.pd\n> >> index 7b652afb43d..8eece2223f9 100644\n> >> --- a/gcc/match.pd\n> >> +++ b/gcc/match.pd\n> >> @@ -5367,6 +5367,64 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)\n> >>         @0)))))\n> >>   #endif\n> >>\n> >> +#if GIMPLE\n> >> +/* PR124808: (A >> CST1) CMP CST2 -> A CMP (CST2 << CST1)\n> >> +   Canonicalize non-equality comparisons between a right\n> >> +   shift and a constant, turning it into a comparison\n> >> +   with a constant that is left shifted.  If we view A as:\n> >> +\n> >> +   A: \"|--- CST2 ----|--CST1--|\"\n> >> +\n> >> +   A >> CST1 will be equal to CST2 for all A values in the\n> >> +   range CST2 << CST1 to (CST2 << CST1) | 1s_mask (CST1).\n> >> +\n> >> +   Therefore:\n> >> +   - (A >> CST1) < CST2 -> A < (CST2 << CST1), A must\n> >> +     be smaller than all values from the range;\n> >> +   - (A >> CST1) <= CST2 -> A <= (CST2 << CST1) | mask,\n> >> +     A must be smaller or equal than the range end;\n> >> +   - (A >> CST1) > CST2 -> A > (CST2 << CST1) | mask,\n> >> +     A must be greater than all values from the range;\n> >> +   - (A >> CST1) >= CST2 -> A >= (CST2 << CST1), A must\n> >> +     be greater or equal than the range start.\n> >> +\n> >> +   We're also using \"single_use\" and wrapping around \"if GIMPLE\"\n> >> +   because (1) this class \"VA1 LSHIFT/RSHIFT VAL2 CMP VAL3\" of\n> >> +   optimizations tend to match CTZ|CLZ builtin patterns and we\n> >> +   don't want to trip on them and (2) we will get in the way of\n> >> +   certain optimizations (see ARM's sat-1.c test) that are done\n> >> +   using GENERIC due to how forwprop currently works.  */\n> >> +(for cmp (le lt ge gt)\n> >> + (simplify\n> >> +  (cmp (rshift@3 @0 INTEGER_CST@1) INTEGER_CST@2)\n> >> +  (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))\n> >> +       && single_use (@3)\n> >\n> > I think with this being gimple only we can keep `:s` on the rshift.\n> > Can you see if that works?\n>\n> It doesn't work unfortunately.  If we change the patch to use :s :\n\nOh yes because of the way `:s` works (I had to read genmatch to\nremember how this thing works). It is trying to prevent doing 2->2 or\n3->2 \"combings\"/simplifications.\nBut since here we are creating a simplified expression and not pushing\nto the sequence, `:s` will not reject it so\nyou need the explicit single_use check.\n\nSo v3 is ok for stage 1 without any changes.\n\nThanks,\nAndrew Pinski\n\n\n>\n> @@ -5396,9 +5396,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)\n>      using GENERIC due to how forwprop currently works.  */\n>   (for cmp (le lt ge gt)\n>    (simplify\n> -  (cmp (rshift@3 @0 INTEGER_CST@1) INTEGER_CST@2)\n> +  (cmp (rshift:s @0 INTEGER_CST@1) INTEGER_CST@2)\n>     (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))\n> -       && single_use (@3)\n>          && tree_fits_uhwi_p (@1)\n>          && tree_to_uhwi (@1) < TYPE_PRECISION (TREE_TYPE (@0))\n>          && tree_int_cst_sgn (@2) >= 0\n>\n>\n> The 'optimized' dump from sat-1.c won't emit MIN_EXPR and MAX_EXPR.  E.g.\n> for 'ss2':\n>\n> intD.7 ss2D.4609 (intD.7 xD.4608)\n> {\n>    intD.7 x_2(D) = xD.4608;\n>    intD.7 _1;\n>    intD.7 _4;\n>    intD.7 _5;\n>\n> ;;   basic block 2, loop depth 0, count 1073741824 (estimated locally, freq 1.0000), maybe hot\n> ;;    prev block 0, next block 3, flags: (NEW, REACHABLE, VISITED)\n> ;;    pred:       ENTRY [always]  count:1073741824 (estimated locally, freq 1.0000) (FALLTHRU,EXECUTABLE)\n>    if (x_2(D) > 2047)\n>      goto <bb 4>; [34.00%]\n>    else\n>      goto <bb 3>; [66.00%]\n> ;;    succ:       4 [34.0% (guessed)]  count:365072224 (estimated locally, freq 0.3400) (TRUE_VALUE,EXECUTABLE)\n> ;;                3 [66.0% (guessed)]  count:708669600 (estimated locally, freq 0.6600) (FALSE_VALUE,EXECUTABLE)\n>\n> ;;   basic block 3, loop depth 0, count 708669600 (estimated locally, freq 0.6600), maybe hot\n> ;;    prev block 2, next block 4, flags: (NEW, REACHABLE, VISITED)\n> ;;    pred:       2 [66.0% (guessed)]  count:708669600 (estimated locally, freq 0.6600) (FALSE_VALUE,EXECUTABLE)\n>    # RANGE [irange] int [-67108864, 63]\n>    _1 = x_2(D) >> 5;\n>    # RANGE [irange] int [-64, 63]\n>    _4 = MAX_EXPR <_1, -64>;\n> ;;    succ:       4 [always]  count:708669600 (estimated locally, freq 0.6600) (FALLTHRU,EXECUTABLE)\n>\n> ;;   basic block 4, loop depth 0, count 1073741824 (estimated locally, freq 1.0000), maybe hot\n> ;;    prev block 3, next block 1, flags: (NEW, REACHABLE, VISITED)\n> ;;    pred:       2 [34.0% (guessed)]  count:365072224 (estimated locally, freq 0.3400) (TRUE_VALUE,EXECUTABLE)\n> ;;                3 [always]  count:708669600 (estimated locally, freq 0.6600) (FALLTHRU,EXECUTABLE)\n>    # RANGE [irange] int [-64, 63]\n>    # _5 = PHI <63(2), _4(3)>\n>    # VUSE <.MEM_3(D)>\n>    return _5;\n> ;;    succ:       EXIT [always]  count:1073741824 (estimated locally, freq 1.0000) (EXECUTABLE) test_sat.c:32:10\n>\n> }\n>\n>\n> With the patch as is, same 'ss2' function:\n>\n> intD.7 ss2D.4609 (intD.7 xD.4608)\n> {\n>    intD.7 x_2(D) = xD.4608;\n>    intD.7 _1;\n>    intD.7 _4;\n>    intD.7 _5;\n>\n> ;;   basic block 2, loop depth 0, count 1073741824 (estimated locally, freq 1.0000), maybe hot\n> ;;    prev block 0, next block 1, flags: (NEW, REACHABLE, VISITED)\n> ;;    pred:       ENTRY [always]  count:1073741824 (estimated locally, freq 1.0000) (FALLTHRU,EXECUTABLE)\n>    # RANGE [irange] int [-67108864, 67108863]\n>    _1 = x_2(D) >> 5;\n>    # RANGE [irange] int [-64, 67108863]\n>    _4 = MAX_EXPR <_1, -64>;\n>    # RANGE [irange] int [-64, 63]\n>    _5 = MIN_EXPR <_4, 63>;\n>    # VUSE <.MEM_3(D)>\n>    return _5;\n> ;;    succ:       EXIT [always]  count:1073741824 (estimated locally, freq 1.0000) (EXECUTABLE) test_sat.c:32:10\n>\n> }\n>\n>\n> Not sure why but seems that we need both \"#if GIMPLE\" and the explicit\n> single_use() check. Thanks,\n>\n> Daniel\n>\n>\n>\n>\n>\n> > Otherwise this is ok (for stage 1).\n> >\n> > Thanks,\n> > Andrew\n> >\n> >> +       && tree_fits_uhwi_p (@1)\n> >> +       && tree_to_uhwi (@1) < TYPE_PRECISION (TREE_TYPE (@0))\n> >> +       && tree_int_cst_sgn (@2) >= 0\n> >> +       /* If @2 is nonzero check if we'll overflow when doing\n> >> +         @2 << @1 by doing a wi::lshift and checking if the\n> >> +         result is zero (i.e. overflow).  */\n> >> +       && (wi::to_wide (@2) == 0\n> >> +          || !wi::eq_p (wi::lshift (wi::to_wide (@2), wi::to_wide (@1)),\n> >> +                        wi::zero (TYPE_PRECISION (TREE_TYPE (@2))))))\n> >> +\n> >> +   /* No need to set the lower @1 bits of the resulting\n> >> +      lshift for \"<\" and \">=\" comparisons.  */\n> >> +   (if (cmp == LT_EXPR || cmp == GE_EXPR)\n> >> +    (cmp @0 (lshift @2 @1))\n> >> +\n> >> +     /* For \"<=\" and \">\" set the lower @1 lshift bits.  */\n> >> +     (with {\n> >> +       tree type2 = TREE_TYPE (@2);\n> >> +       unsigned prec = TYPE_PRECISION (type2);\n> >> +       unsigned mask_len = TREE_INT_CST_LOW (@1);\n> >> +       wide_int cst1_mask = wi::mask (mask_len, false, prec);\n> >> +      }\n> >> +       (cmp @0 (bit_ior (lshift @2 @1)\n> >> +                       { wide_int_to_tree (type2, cst1_mask); })))))))\n> >> +#endif\n> >> +\n> >>   /* Rewrite an LROTATE_EXPR by a constant into an\n> >>      RROTATE_EXPR by a new constant.  */\n> >>   (simplify\n> >> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c\n> >> new file mode 100644\n> >> index 00000000000..bfab8109ce6\n> >> --- /dev/null\n> >> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c\n> >> @@ -0,0 +1,44 @@\n> >> +/* { dg-additional-options -O2 } */\n> >> +/* { dg-additional-options -fdump-tree-forwprop1 } */\n> >> +\n> >> +long* SetupPrecalculatedData1 (long* a) {\n> >> +  long b = 1;\n> >> +  int i;\n> >> +  for (i = 0; i < 64; i++) {\n> >> +    if(i>>3 < 7)\n> >> +      a[i] += (b<<(i+8));\n> >> +  }\n> >> +  return a;\n> >> +}\n> >> +\n> >> +long* SetupPrecalculatedData2 (long* a) {\n> >> +  long b = 1;\n> >> +  int i;\n> >> +  for (i = 0; i <= 64; i++) {\n> >> +    if(i>>3 < 7)\n> >> +      a[i] += (b<<(i+8));\n> >> +  }\n> >> +  return a;\n> >> +}\n> >> +\n> >> +long* SetupPrecalculatedData3 (long* a) {\n> >> +  long b = 1;\n> >> +  int i;\n> >> +  for (i = 0; i < 64; i++) {\n> >> +    if(i>>3 > 7)\n> >> +      a[i] += (b<<(i+8));\n> >> +  }\n> >> +  return a;\n> >> +}\n> >> +\n> >> +long* SetupPrecalculatedData4 (long* a) {\n> >> +  long b = 1;\n> >> +  int i;\n> >> +  for (i = 0; i < 64; i++) {\n> >> +    if(i>>3 >= 7)\n> >> +      a[i] += (b<<(i+8));\n> >> +  }\n> >> +  return a;\n> >> +}\n> >> +\n> >> +/* { dg-final { scan-tree-dump-times \">> 3\" 0 forwprop1 } } */\n> >> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr124808.c b/gcc/testsuite/gcc.dg/tree-ssa/pr124808.c\n> >> new file mode 100644\n> >> index 00000000000..5f3c1f0a8c4\n> >> --- /dev/null\n> >> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr124808.c\n> >> @@ -0,0 +1,78 @@\n> >> +/* { dg-do run } */\n> >> +/* { dg-options \"-O2\" } */\n> >> +\n> >> +void abort(void);\n> >> +\n> >> +/* Macro adapted from builtin-object-size-common.h  */\n> >> +#define FAIL() \\\n> >> +  do { \\\n> >> +    __builtin_printf (\"Failure at line: %d\\n\", __LINE__);      \\\n> >> +    abort();                                                   \\\n> >> +  } while (0)\n> >> +\n> >> +#define SHIFTVAL 3\n> >> +#define CMPVAL 1\n> >> +\n> >> +long setValue1 (long in)\n> >> +{\n> >> +  if (in >> SHIFTVAL < CMPVAL)\n> >> +    return in += SHIFTVAL;\n> >> +  return -1;\n> >> +}\n> >> +\n> >> +long setValue2 (long in)\n> >> +{\n> >> +  if (in >> SHIFTVAL <= CMPVAL)\n> >> +    return in += SHIFTVAL;\n> >> +  return -1;\n> >> +}\n> >> +\n> >> +long setValue3 (long in)\n> >> +{\n> >> +  if (in >> SHIFTVAL > CMPVAL)\n> >> +    return in += SHIFTVAL;\n> >> +  return -1;\n> >> +}\n> >> +\n> >> +long setValue4 (long in)\n> >> +{\n> >> +  if (in >> SHIFTVAL >= CMPVAL)\n> >> +    return in += SHIFTVAL;\n> >> +  return -1;\n> >> +}\n> >> +\n> >> +int main (void) {\n> >> +  /* setValue1: in << 3 < 1;  */\n> >> +  if (setValue1 (7) != 10)\n> >> +    FAIL ();\n> >> +  if (setValue1 (8) != -1)\n> >> +    FAIL ();\n> >> +\n> >> +  /* setValue2: in << 3 <= 1;  */\n> >> +  if (setValue2 (7) != 10)\n> >> +    FAIL ();\n> >> +  if (setValue2 (8) != 11)\n> >> +    FAIL ();\n> >> +  if (setValue2 (15) != 18)\n> >> +    FAIL ();\n> >> +  if (setValue2 (16) != -1)\n> >> +    FAIL ();\n> >> +\n> >> +  /* setValue3: in << 3 > 1;  */\n> >> +  if (setValue3 (15) != -1)\n> >> +    FAIL ();\n> >> +  if (setValue3 (16) != 19)\n> >> +    FAIL ();\n> >> +\n> >> +  /* setValue4: in << 3 >= 1;  */\n> >> +  if (setValue4 (7) != -1)\n> >> +    FAIL ();\n> >> +  if (setValue4 (8) != 11)\n> >> +    FAIL ();\n> >> +  if (setValue4 (15) != 18)\n> >> +    FAIL ();\n> >> +  if (setValue4 (16) != 19)\n> >> +    FAIL ();\n> >> +\n> >> +  return 0;\n> >> +}\n> >> --\n> >> 2.43.0\n> >>\n>","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=UoD3uLOw;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=d/vxtua/;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=UoD3uLOw;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=d/vxtua/","sourceware.org; dmarc=none (p=none dis=none)\n header.from=oss.qualcomm.com","sourceware.org;\n spf=pass smtp.mailfrom=oss.qualcomm.com","server2.sourceware.org;\n arc=pass smtp.remote-ip=205.220.180.131"],"Received":["from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fxQRl4d9Xz1yD3\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 03:46:26 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 1D9CB4C515FC\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 17:46:24 +0000 (GMT)","from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com\n [205.220.180.131])\n by sourceware.org (Postfix) with ESMTPS id 6B2564B9DB70\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 17:45:53 +0000 (GMT)","from pps.filterd (m0279871.ppops.net [127.0.0.1])\n by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 63GECuDN2575990\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 17:45:52 GMT","from mail-dy1-f197.google.com (mail-dy1-f197.google.com\n [74.125.82.197])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4djv27j4sy-1\n (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 17:45:52 +0000 (GMT)","by mail-dy1-f197.google.com with SMTP id\n 5a478bee46e88-2c0f6593ef5so11418454eec.1\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 10:45:52 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 1D9CB4C515FC","OpenDKIM Filter v2.11.0 sourceware.org 6B2564B9DB70"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 6B2564B9DB70","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 6B2564B9DB70","ARC-Seal":["i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1776361553; cv=pass;\n b=WoDNScDYCMtxwx9bszfg2eSr+tsdd6hriJPlRWJ5ZVmnLxwbKrqnBbYpwVuyMLciTu9YK8D5iZy0+HF5v0fE6mJCjvRQkleFvc/0o1tscXcuSOTMbvXXwJtZjyCGmC2oul6/4QheHkpSSpEd/Ue33dSlwgOQJtuPNd9smXjQG8g=","i=1; a=rsa-sha256; t=1776361551; cv=none;\n d=google.com; s=arc-20240605;\n b=Sqt/gVXOwnKbahRALqUfUluGr4rynSGiw/lkLEpXIF/HYVy5XpemU9YP6JobDftZoT\n h8AxILoDpGcgysHdw74gguhc2MpTgk41XUjF2ExmcoX48t6iLhgjDp5oSUzohk0CZk32\n UDEuTMtC9dhE++cYyhOQahIoIej72Q3B55aPmEoWgh0W6eN+ZQ5OyvtH3Fg31bxjm4zy\n sa36JLHbX06wqF9i8Yu19KGtIZI4drv88b/X/iMsYs23Sjn8G4Xko35iisVSD/bPvLD3\n u6YJo/x3+AyTcFhsn43pjeWgg/on2ig6ic2frF10t1JJc9pjLWaE7FZYvAW3q4MSE4CE\n E/gg=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776361553; c=relaxed/simple;\n bh=HeLDb0selIH95zHXzULW97EZFx56ZsOXGfrWc3F2+ek=;\n h=DKIM-Signature:DKIM-Signature:MIME-Version:From:Date:Message-ID:\n Subject:To;\n b=pQA+AIPTCnl9iNkfWvtCvg1uv0VpB0QTJg1GKuwRl2wZZ5xHE9BeO3XdlCya7ooy86jA6b93qXq6KAqKTx2HtwFU6POTaeMU5k657X1vt4vz8FpbO+CYVM7wdWR70puyKmcuAJhqmhIz1pV4Bzfp3laxmp/5hzl1yUFJn5dF6lI=","i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:dkim-signature;\n bh=uWdU3VykGRTYLE/ubaK7a0N94jrSxEMEN4VfsyUcyfU=;\n fh=6iYHMs1AWdlXsix1dekPdk3naIOb8QIZEI8h8UsuOtQ=;\n b=ZNsnEWbniviNWLG+GBqpKIoGOR+FLI1fEC8XOEyDRv0lEtzRw7lg7PJZQVdUQxK8Y0\n Ar2L75bkjCiE05CpLs39vtkrWlmB9SC9O7cxN+JudFcIiE5COnXtVkrNv5ONbqdcFOAu\n 7YmQaNVKto6/xNgBCq+nJnNt53kht9TCecI0yN+Zc3J60NZj8kAX9Ey2/OLTkEgbjhZ5\n mVXmWd0PJLlb5tdg362UJuEb1c9hp1wJfqBaclxBwl5P8lS92iRh1orJH4etpNy6bctR\n 8T1ch7czuaE1FoQmawXVkKa8nW3BCrhrdun+fZIZf9KwBWkadtdHMGrsLUrZz2UvoaEx\n TxQA==; darn=gcc.gnu.org"],"ARC-Authentication-Results":["i=2; server2.sourceware.org","i=1; mx.google.com; arc=none"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n cc:content-transfer-encoding:content-type:date:from:in-reply-to\n :message-id:mime-version:references:subject:to; s=qcppdkim1; bh=\n uWdU3VykGRTYLE/ubaK7a0N94jrSxEMEN4VfsyUcyfU=; b=UoD3uLOwxKeeRzrc\n tLwmGGEmMi6BaOeeq5JYnaTpu7yLkCehQi9HaPSASnge8ttRS+qqwpgEC9b2xhgi\n +HitJ5Qji4SYLZa1Wr40vnFoP7Co7fIWlOJlD4YYvuE0ENq3Br8HxtdGPrR6M9Kh\n U45CLY0G1U8nMDMEFuN7H51ryGUG6ogN7kOiLrRrP+xL2DWMhT3ArI0B3H+h5T9l\n dg3dms94ArJ9yXFrsqY9DETmH4OUEfb6EqYx2hUEIeqr5Yfr60aFp1nEF/opckZt\n KrF6Uzd80IawKTfyoOzUs+MRnV2opeuaY/J2PJlgK/zHUYoy7stLEkQjtE1tZKQQ\n S+Pl2w==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1776361551; x=1776966351; darn=gcc.gnu.org;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:from:to:cc:subject:date\n :message-id:reply-to;\n bh=uWdU3VykGRTYLE/ubaK7a0N94jrSxEMEN4VfsyUcyfU=;\n b=d/vxtua/0DU7EwHT9ZvK5sw6tjgOeWV6HSa79Nhx0cx9g4sdReJXz9IPIrMgFhrsqb\n ViJ+f7sNH6QAAAgNsJKvXDG11Oz9XIxOW4JGxXSgei/UOfDt1xeLQoVCfdxlnVyfRHjz\n neuEnzudUFJoCo2z0KX3d6gFqTzBM+DevccFqK3wsdhJF3r+NSWKCYPE1A5ka0adqmxT\n lPsb4VbLkGdscxPCRW1PTXGF5HX7BRCbkfSIEeXIkKMvZT73mUqPgw+1VrSUbLiJzS40\n jvlB2OH0xZ+3inJzQLYKEOBfBDQXx7XLpCwj6BqTJ6aNm5EJiSZJEV1zXYuUI1O6sFxv\n W/Og=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776361551; x=1776966351;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=uWdU3VykGRTYLE/ubaK7a0N94jrSxEMEN4VfsyUcyfU=;\n b=RC1tMyoHqpngvZOWOh93ffoACMafatwzyTHczAt/ne2/b2Heu+0bWPVdLPexFquQZx\n yxrr+7Re1jv3YU0eBYXNBkAto3S931hC7JNE/ur7/ehgEg+Z4p0mWd/RYl4DlajPlCyE\n heu712qbJhmp0dzYq1YbyittcbVdAg67ch6KOwFcE5xlQpaIaS3Vs+u5BC1gRpc6330R\n HrGUHzddbyTSIpAMwAkBn6EuTyLSLTCuDc/OwptMz7Qo/5d+2aBFp4BP9e3CyroCcbp6\n r3TGPK0WgMv3NKdkG610vN3VndvVqDPNFyGpvyMckRB7bG3sXB8ZtLMpIAO0daJL0OB9\n bkPw==","X-Gm-Message-State":"AOJu0YzFHUe/9+MIuKmgaWwYz9+IwjozwHMmNukkDRnmFx8gpJoR0CZ2\n pQSVtGm0/8NMHPfQnnPRGvc4FNSv65fQ62fzbz218rC+08z0IEdPSmF6EcFJwU+rTspL0UtEVV3\n 509LjUWkLIjRsQgHIUUyB7g50bqreaS2aK1UdDPgN7HffaU0/HUNa/WobergBILAbd6fM0T5fQ2\n QkK+LoOEX8jLJ9IZxx6xc/nvxO/mIOtW/tOBI=","X-Gm-Gg":"AeBDietIRkv+liG6sMphWPoWo7Hm2xWzniJeFl37T3mMGage5ysdATug4nCgc2mcoMx\n VDJe0yjBOq6pp9x/Z1D4NxJspN2ClDVvqbW6412MnOMFdvdLCasu2DsGQFw6t2Z+Y+qWDCxI/j8\n MqbKrurcYB50wXSQdQDuCJPEUGmRkUbqeieY3I/44M3O9CREmoe41TOkheiLBAOFzHOkiN50Jyf\n da3F8McBXY6BOM=","X-Received":["by 2002:a05:693c:3008:b0:2d9:db50:c6a5 with SMTP id\n 5a478bee46e88-2e2e09347b8mr138881eec.0.1776361551232;\n Thu, 16 Apr 2026 10:45:51 -0700 (PDT)","by 2002:a05:693c:3008:b0:2d9:db50:c6a5 with SMTP id\n 5a478bee46e88-2e2e09347b8mr138863eec.0.1776361550569; Thu, 16 Apr 2026\n 10:45:50 -0700 (PDT)"],"MIME-Version":"1.0","References":"<20260416122941.286122-1-daniel.barboza@oss.qualcomm.com>\n <CALvbMcCFQXXX=cfwb7fqPZ5-bF+X7nf7tgQ_xA_kNArBS63V1A@mail.gmail.com>\n <f87c6c59-8bb8-4c20-a0a9-c33164f8c53a@oss.qualcomm.com>","In-Reply-To":"<f87c6c59-8bb8-4c20-a0a9-c33164f8c53a@oss.qualcomm.com>","From":"Andrew Pinski <andrew.pinski@oss.qualcomm.com>","Date":"Thu, 16 Apr 2026 10:45:39 -0700","X-Gm-Features":"AQROBzD7_KMh6bk_7R-oyeY4_huhMjSHUQIfcCI3nNTOC3gX7aupsgDbYnK9NrA","Message-ID":"\n <CALvbMcCXupBJsbH65c37J6t1c2RGdKr6+fz=kZfN+bQtnrs6XQ@mail.gmail.com>","Subject":"Re: [PATCH v3] match.pd: right shift compare canonicalization\n [PR124808]","To":"Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>","Cc":"gcc-patches@gcc.gnu.org, jeffrey.law@oss.qualcomm.com","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","X-Authority-Analysis":"v=2.4 cv=PJQ/P/qC c=1 sm=1 tr=0 ts=69e12050 cx=c_pps\n a=Uww141gWH0fZj/3QKPojxA==:117 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10\n a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22\n a=3WHJM1ZQz_JShphwDgj5:22 a=mDV3o1hIAAAA:8 a=EUspDBNiAAAA:8\n a=EnjYP69xi3gGDWt0oI8A:9 a=QEXdDO2ut3YA:10 a=PxkB5W3o20Ba91AHUih5:22","X-Proofpoint-GUID":"O574iQfihbE-jNzChPaLOTmSS0nZkM2Z","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDE2MDE2OSBTYWx0ZWRfXwKNEksHmutFT\n 7g/inJN0fWNt7eS5FU8QQw66UNE/AV471gybOWhqag4UHlcs8BXsPS7E+wC+R5kVpr33i9N/mMk\n acEt1k2zXutNv3AdlGaChmJrqnicaI9Nvl8nSNy+1LdLgS763oiYSqWX+OdBTrsaeDDJhPyOE+o\n CGtkpYT4iGXegj0ImiEnSvNup+BbhvdUgReh1YGqG+OaUIaLNPeW5sWz8FubgXr0TS0m5JUkSNk\n IEe5FtcoKQ7+oi/potF6QN+IQnSOpfNtuqpcKf/dcoy++qQJPgYmisFWmq+Aai+jlD9AgR2fYyS\n aV02eB2Sy9LkGaC/9JSDBsNpV9I/SwVnRc8eypn3kw1dRr4ZD/goF7ZLKebRF6khJfj3i8qT2MS\n U4T2nKET31A6le7sViDJjp6Jpu/vKXCF8EBZcT4e6aNwvC+8SebEv4MvdxILkLv/ZsNaAAnjNKC\n sOrjopR/HOADV0f7zEA==","X-Proofpoint-ORIG-GUID":"O574iQfihbE-jNzChPaLOTmSS0nZkM2Z","X-Proofpoint-Virus-Version":"vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-04-16_03,2026-04-16_03,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n malwarescore=0 suspectscore=0 spamscore=0 adultscore=0 phishscore=0\n impostorscore=0 bulkscore=0 priorityscore=1501 clxscore=1015\n lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc=\n route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604070000\n definitions=main-2604160169","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}},{"id":3678395,"web_url":"http://patchwork.ozlabs.org/comment/3678395/","msgid":"<CALvbMcD8T8AgiNgaK4FPnCtOca7uGviFP=6LdfkLw-xQ1674KQ@mail.gmail.com>","list_archive_url":null,"date":"2026-04-16T21:25:01","subject":"Re: [PATCH v3] match.pd: right shift compare canonicalization\n [PR124808]","submitter":{"id":91428,"url":"http://patchwork.ozlabs.org/api/people/91428/","name":"Andrew Pinski","email":"andrew.pinski@oss.qualcomm.com"},"content":"On Thu, Apr 16, 2026 at 10:45 AM Andrew Pinski\n<andrew.pinski@oss.qualcomm.com> wrote:\n>\n> On Thu, Apr 16, 2026 at 8:41 AM Daniel Henrique Barboza\n> <daniel.barboza@oss.qualcomm.com> wrote:\n> >\n> >\n> >\n> > On 4/16/2026 11:50 AM, Andrew Pinski wrote:\n> > > On Thu, Apr 16, 2026 at 5:29 AM Daniel Henrique Barboza\n> > > <daniel.barboza@oss.qualcomm.com> wrote:\n> > >>\n> > >> From: Daniel Barboza <daniel.barboza@oss.qualcomm.com>\n> > >>\n> > >> Canonicalize right shift non-equality comparisons with constants by\n> > >> turn them into a comparison with a left shifted constant.  Assuming the\n> > >> generic format:\n> > >>\n> > >> (A >> CST1) CMP CST2\n> > >>\n> > >> For CMP (<, >=) we'll compare A with CST2 left shifted by CST1:\n> > >>\n> > >> - (A >> CST1) < CST2  -> A < (CST2 << CST1)\n> > >> - (A >> CST1) >= CST2 -> A >= (CST2 << CST1)\n> > >>\n> > >> And for CMP (<=, >) we need to IOR the lower CST1 bits from the left\n> > >> shift:\n> > >>\n> > >> - (A >> CST1) <= CST2 -> A <= (CST2 << CST1) | mask\n> > >> - (A >> CST1) > CST2  -> A > (CST2 << CST1) | mask\n> > >>\n> > >> Given that the right hand side changes involves just constants, in the\n> > >> end we'll replace a rshift + cmp with just a cmp.\n> > >>\n> > >> Bootstrapped and regression tested in x86, aarch64 and RISC-V.\n> > >>\n> > >>          PR tree-optimization/124808\n> > >>\n> > >> gcc/ChangeLog:\n> > >>\n> > >>          * match.pd(`(A >> CST1) CMP CST2`): New pattern.\n> > >>\n> > >> gcc/testsuite/ChangeLog:\n> > >>\n> > >>          * gcc.dg/tree-ssa/pr124808-2.c: New test.\n> > >>          * gcc.dg/tree-ssa/pr124808.c: New test.\n> > >> ---\n> > >>\n> > >> Changes from v2:\n> > >> - added \"#if GIMPLE\" and \"single_use\" conditions in the pattern\n> > >> - changed pr124808-2.c to scan 'forwprop1' dump instead of 'gimple'\n> > >> - reverted all changes made in sat-1.c\n> > >> - reverted all changes made in pr104479.c\n> > >> - v2 link: https://gcc.gnu.org/pipermail/gcc-patches/2026-April/713005.html\n> > >>\n> > >>   gcc/match.pd                               | 58 ++++++++++++++++\n> > >>   gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c | 44 ++++++++++++\n> > >>   gcc/testsuite/gcc.dg/tree-ssa/pr124808.c   | 78 ++++++++++++++++++++++\n> > >>   3 files changed, 180 insertions(+)\n> > >>   create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c\n> > >>   create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr124808.c\n> > >>\n> > >> diff --git a/gcc/match.pd b/gcc/match.pd\n> > >> index 7b652afb43d..8eece2223f9 100644\n> > >> --- a/gcc/match.pd\n> > >> +++ b/gcc/match.pd\n> > >> @@ -5367,6 +5367,64 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)\n> > >>         @0)))))\n> > >>   #endif\n> > >>\n> > >> +#if GIMPLE\n> > >> +/* PR124808: (A >> CST1) CMP CST2 -> A CMP (CST2 << CST1)\n> > >> +   Canonicalize non-equality comparisons between a right\n> > >> +   shift and a constant, turning it into a comparison\n> > >> +   with a constant that is left shifted.  If we view A as:\n> > >> +\n> > >> +   A: \"|--- CST2 ----|--CST1--|\"\n> > >> +\n> > >> +   A >> CST1 will be equal to CST2 for all A values in the\n> > >> +   range CST2 << CST1 to (CST2 << CST1) | 1s_mask (CST1).\n> > >> +\n> > >> +   Therefore:\n> > >> +   - (A >> CST1) < CST2 -> A < (CST2 << CST1), A must\n> > >> +     be smaller than all values from the range;\n> > >> +   - (A >> CST1) <= CST2 -> A <= (CST2 << CST1) | mask,\n> > >> +     A must be smaller or equal than the range end;\n> > >> +   - (A >> CST1) > CST2 -> A > (CST2 << CST1) | mask,\n> > >> +     A must be greater than all values from the range;\n> > >> +   - (A >> CST1) >= CST2 -> A >= (CST2 << CST1), A must\n> > >> +     be greater or equal than the range start.\n> > >> +\n> > >> +   We're also using \"single_use\" and wrapping around \"if GIMPLE\"\n> > >> +   because (1) this class \"VA1 LSHIFT/RSHIFT VAL2 CMP VAL3\" of\n> > >> +   optimizations tend to match CTZ|CLZ builtin patterns and we\n> > >> +   don't want to trip on them and (2) we will get in the way of\n> > >> +   certain optimizations (see ARM's sat-1.c test) that are done\n> > >> +   using GENERIC due to how forwprop currently works.  */\n> > >> +(for cmp (le lt ge gt)\n> > >> + (simplify\n> > >> +  (cmp (rshift@3 @0 INTEGER_CST@1) INTEGER_CST@2)\n> > >> +  (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))\n> > >> +       && single_use (@3)\n> > >\n> > > I think with this being gimple only we can keep `:s` on the rshift.\n> > > Can you see if that works?\n> >\n> > It doesn't work unfortunately.  If we change the patch to use :s :\n>\n> Oh yes because of the way `:s` works (I had to read genmatch to\n> remember how this thing works). It is trying to prevent doing 2->2 or\n> 3->2 \"combings\"/simplifications.\n> But since here we are creating a simplified expression and not pushing\n> to the sequence, `:s` will not reject it so\n> you need the explicit single_use check.\n>\n> So v3 is ok for stage 1 without any changes.\n\nBy the way the forwprop handling is in\nforward_propagate_into_comparison_1 and the removal of it is recorded\nas https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120206. I had a start\non removing it last year but I didn't finish it (as I ran into a\ndifferent issue). Maybe this year I can finish it up but with all of\nthe other stuff I am currently working on I am not sure.\nforward_propagate_into_comparison_1 dates from pre-match-and-simplify;\neven before gimple tuples was around (though changed/improved since\nthen). So removing it will be a nice cleanup.\n\nThanks,\nAndrea\n\n>\n> Thanks,\n> Andrew Pinski\n>\n>\n> >\n> > @@ -5396,9 +5396,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)\n> >      using GENERIC due to how forwprop currently works.  */\n> >   (for cmp (le lt ge gt)\n> >    (simplify\n> > -  (cmp (rshift@3 @0 INTEGER_CST@1) INTEGER_CST@2)\n> > +  (cmp (rshift:s @0 INTEGER_CST@1) INTEGER_CST@2)\n> >     (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))\n> > -       && single_use (@3)\n> >          && tree_fits_uhwi_p (@1)\n> >          && tree_to_uhwi (@1) < TYPE_PRECISION (TREE_TYPE (@0))\n> >          && tree_int_cst_sgn (@2) >= 0\n> >\n> >\n> > The 'optimized' dump from sat-1.c won't emit MIN_EXPR and MAX_EXPR.  E.g.\n> > for 'ss2':\n> >\n> > intD.7 ss2D.4609 (intD.7 xD.4608)\n> > {\n> >    intD.7 x_2(D) = xD.4608;\n> >    intD.7 _1;\n> >    intD.7 _4;\n> >    intD.7 _5;\n> >\n> > ;;   basic block 2, loop depth 0, count 1073741824 (estimated locally, freq 1.0000), maybe hot\n> > ;;    prev block 0, next block 3, flags: (NEW, REACHABLE, VISITED)\n> > ;;    pred:       ENTRY [always]  count:1073741824 (estimated locally, freq 1.0000) (FALLTHRU,EXECUTABLE)\n> >    if (x_2(D) > 2047)\n> >      goto <bb 4>; [34.00%]\n> >    else\n> >      goto <bb 3>; [66.00%]\n> > ;;    succ:       4 [34.0% (guessed)]  count:365072224 (estimated locally, freq 0.3400) (TRUE_VALUE,EXECUTABLE)\n> > ;;                3 [66.0% (guessed)]  count:708669600 (estimated locally, freq 0.6600) (FALSE_VALUE,EXECUTABLE)\n> >\n> > ;;   basic block 3, loop depth 0, count 708669600 (estimated locally, freq 0.6600), maybe hot\n> > ;;    prev block 2, next block 4, flags: (NEW, REACHABLE, VISITED)\n> > ;;    pred:       2 [66.0% (guessed)]  count:708669600 (estimated locally, freq 0.6600) (FALSE_VALUE,EXECUTABLE)\n> >    # RANGE [irange] int [-67108864, 63]\n> >    _1 = x_2(D) >> 5;\n> >    # RANGE [irange] int [-64, 63]\n> >    _4 = MAX_EXPR <_1, -64>;\n> > ;;    succ:       4 [always]  count:708669600 (estimated locally, freq 0.6600) (FALLTHRU,EXECUTABLE)\n> >\n> > ;;   basic block 4, loop depth 0, count 1073741824 (estimated locally, freq 1.0000), maybe hot\n> > ;;    prev block 3, next block 1, flags: (NEW, REACHABLE, VISITED)\n> > ;;    pred:       2 [34.0% (guessed)]  count:365072224 (estimated locally, freq 0.3400) (TRUE_VALUE,EXECUTABLE)\n> > ;;                3 [always]  count:708669600 (estimated locally, freq 0.6600) (FALLTHRU,EXECUTABLE)\n> >    # RANGE [irange] int [-64, 63]\n> >    # _5 = PHI <63(2), _4(3)>\n> >    # VUSE <.MEM_3(D)>\n> >    return _5;\n> > ;;    succ:       EXIT [always]  count:1073741824 (estimated locally, freq 1.0000) (EXECUTABLE) test_sat.c:32:10\n> >\n> > }\n> >\n> >\n> > With the patch as is, same 'ss2' function:\n> >\n> > intD.7 ss2D.4609 (intD.7 xD.4608)\n> > {\n> >    intD.7 x_2(D) = xD.4608;\n> >    intD.7 _1;\n> >    intD.7 _4;\n> >    intD.7 _5;\n> >\n> > ;;   basic block 2, loop depth 0, count 1073741824 (estimated locally, freq 1.0000), maybe hot\n> > ;;    prev block 0, next block 1, flags: (NEW, REACHABLE, VISITED)\n> > ;;    pred:       ENTRY [always]  count:1073741824 (estimated locally, freq 1.0000) (FALLTHRU,EXECUTABLE)\n> >    # RANGE [irange] int [-67108864, 67108863]\n> >    _1 = x_2(D) >> 5;\n> >    # RANGE [irange] int [-64, 67108863]\n> >    _4 = MAX_EXPR <_1, -64>;\n> >    # RANGE [irange] int [-64, 63]\n> >    _5 = MIN_EXPR <_4, 63>;\n> >    # VUSE <.MEM_3(D)>\n> >    return _5;\n> > ;;    succ:       EXIT [always]  count:1073741824 (estimated locally, freq 1.0000) (EXECUTABLE) test_sat.c:32:10\n> >\n> > }\n> >\n> >\n> > Not sure why but seems that we need both \"#if GIMPLE\" and the explicit\n> > single_use() check. Thanks,\n> >\n> > Daniel\n> >\n> >\n> >\n> >\n> >\n> > > Otherwise this is ok (for stage 1).\n> > >\n> > > Thanks,\n> > > Andrew\n> > >\n> > >> +       && tree_fits_uhwi_p (@1)\n> > >> +       && tree_to_uhwi (@1) < TYPE_PRECISION (TREE_TYPE (@0))\n> > >> +       && tree_int_cst_sgn (@2) >= 0\n> > >> +       /* If @2 is nonzero check if we'll overflow when doing\n> > >> +         @2 << @1 by doing a wi::lshift and checking if the\n> > >> +         result is zero (i.e. overflow).  */\n> > >> +       && (wi::to_wide (@2) == 0\n> > >> +          || !wi::eq_p (wi::lshift (wi::to_wide (@2), wi::to_wide (@1)),\n> > >> +                        wi::zero (TYPE_PRECISION (TREE_TYPE (@2))))))\n> > >> +\n> > >> +   /* No need to set the lower @1 bits of the resulting\n> > >> +      lshift for \"<\" and \">=\" comparisons.  */\n> > >> +   (if (cmp == LT_EXPR || cmp == GE_EXPR)\n> > >> +    (cmp @0 (lshift @2 @1))\n> > >> +\n> > >> +     /* For \"<=\" and \">\" set the lower @1 lshift bits.  */\n> > >> +     (with {\n> > >> +       tree type2 = TREE_TYPE (@2);\n> > >> +       unsigned prec = TYPE_PRECISION (type2);\n> > >> +       unsigned mask_len = TREE_INT_CST_LOW (@1);\n> > >> +       wide_int cst1_mask = wi::mask (mask_len, false, prec);\n> > >> +      }\n> > >> +       (cmp @0 (bit_ior (lshift @2 @1)\n> > >> +                       { wide_int_to_tree (type2, cst1_mask); })))))))\n> > >> +#endif\n> > >> +\n> > >>   /* Rewrite an LROTATE_EXPR by a constant into an\n> > >>      RROTATE_EXPR by a new constant.  */\n> > >>   (simplify\n> > >> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c\n> > >> new file mode 100644\n> > >> index 00000000000..bfab8109ce6\n> > >> --- /dev/null\n> > >> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr124808-2.c\n> > >> @@ -0,0 +1,44 @@\n> > >> +/* { dg-additional-options -O2 } */\n> > >> +/* { dg-additional-options -fdump-tree-forwprop1 } */\n> > >> +\n> > >> +long* SetupPrecalculatedData1 (long* a) {\n> > >> +  long b = 1;\n> > >> +  int i;\n> > >> +  for (i = 0; i < 64; i++) {\n> > >> +    if(i>>3 < 7)\n> > >> +      a[i] += (b<<(i+8));\n> > >> +  }\n> > >> +  return a;\n> > >> +}\n> > >> +\n> > >> +long* SetupPrecalculatedData2 (long* a) {\n> > >> +  long b = 1;\n> > >> +  int i;\n> > >> +  for (i = 0; i <= 64; i++) {\n> > >> +    if(i>>3 < 7)\n> > >> +      a[i] += (b<<(i+8));\n> > >> +  }\n> > >> +  return a;\n> > >> +}\n> > >> +\n> > >> +long* SetupPrecalculatedData3 (long* a) {\n> > >> +  long b = 1;\n> > >> +  int i;\n> > >> +  for (i = 0; i < 64; i++) {\n> > >> +    if(i>>3 > 7)\n> > >> +      a[i] += (b<<(i+8));\n> > >> +  }\n> > >> +  return a;\n> > >> +}\n> > >> +\n> > >> +long* SetupPrecalculatedData4 (long* a) {\n> > >> +  long b = 1;\n> > >> +  int i;\n> > >> +  for (i = 0; i < 64; i++) {\n> > >> +    if(i>>3 >= 7)\n> > >> +      a[i] += (b<<(i+8));\n> > >> +  }\n> > >> +  return a;\n> > >> +}\n> > >> +\n> > >> +/* { dg-final { scan-tree-dump-times \">> 3\" 0 forwprop1 } } */\n> > >> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr124808.c b/gcc/testsuite/gcc.dg/tree-ssa/pr124808.c\n> > >> new file mode 100644\n> > >> index 00000000000..5f3c1f0a8c4\n> > >> --- /dev/null\n> > >> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr124808.c\n> > >> @@ -0,0 +1,78 @@\n> > >> +/* { dg-do run } */\n> > >> +/* { dg-options \"-O2\" } */\n> > >> +\n> > >> +void abort(void);\n> > >> +\n> > >> +/* Macro adapted from builtin-object-size-common.h  */\n> > >> +#define FAIL() \\\n> > >> +  do { \\\n> > >> +    __builtin_printf (\"Failure at line: %d\\n\", __LINE__);      \\\n> > >> +    abort();                                                   \\\n> > >> +  } while (0)\n> > >> +\n> > >> +#define SHIFTVAL 3\n> > >> +#define CMPVAL 1\n> > >> +\n> > >> +long setValue1 (long in)\n> > >> +{\n> > >> +  if (in >> SHIFTVAL < CMPVAL)\n> > >> +    return in += SHIFTVAL;\n> > >> +  return -1;\n> > >> +}\n> > >> +\n> > >> +long setValue2 (long in)\n> > >> +{\n> > >> +  if (in >> SHIFTVAL <= CMPVAL)\n> > >> +    return in += SHIFTVAL;\n> > >> +  return -1;\n> > >> +}\n> > >> +\n> > >> +long setValue3 (long in)\n> > >> +{\n> > >> +  if (in >> SHIFTVAL > CMPVAL)\n> > >> +    return in += SHIFTVAL;\n> > >> +  return -1;\n> > >> +}\n> > >> +\n> > >> +long setValue4 (long in)\n> > >> +{\n> > >> +  if (in >> SHIFTVAL >= CMPVAL)\n> > >> +    return in += SHIFTVAL;\n> > >> +  return -1;\n> > >> +}\n> > >> +\n> > >> +int main (void) {\n> > >> +  /* setValue1: in << 3 < 1;  */\n> > >> +  if (setValue1 (7) != 10)\n> > >> +    FAIL ();\n> > >> +  if (setValue1 (8) != -1)\n> > >> +    FAIL ();\n> > >> +\n> > >> +  /* setValue2: in << 3 <= 1;  */\n> > >> +  if (setValue2 (7) != 10)\n> > >> +    FAIL ();\n> > >> +  if (setValue2 (8) != 11)\n> > >> +    FAIL ();\n> > >> +  if (setValue2 (15) != 18)\n> > >> +    FAIL ();\n> > >> +  if (setValue2 (16) != -1)\n> > >> +    FAIL ();\n> > >> +\n> > >> +  /* setValue3: in << 3 > 1;  */\n> > >> +  if (setValue3 (15) != -1)\n> > >> +    FAIL ();\n> > >> +  if (setValue3 (16) != 19)\n> > >> +    FAIL ();\n> > >> +\n> > >> +  /* setValue4: in << 3 >= 1;  */\n> > >> +  if (setValue4 (7) != -1)\n> > >> +    FAIL ();\n> > >> +  if (setValue4 (8) != 11)\n> > >> +    FAIL ();\n> > >> +  if (setValue4 (15) != 18)\n> > >> +    FAIL ();\n> > >> +  if (setValue4 (16) != 19)\n> > >> +    FAIL ();\n> > >> +\n> > >> +  return 0;\n> > >> +}\n> > >> --\n> > >> 2.43.0\n> > >>\n> >","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=aKmE1CB1;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=Rt8QiAMi;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256\n header.s=qcppdkim1 header.b=aKmE1CB1;\n\tdkim=pass (2048-bit key,\n unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n header.a=rsa-sha256 header.s=google header.b=Rt8QiAMi","sourceware.org; dmarc=none (p=none dis=none)\n header.from=oss.qualcomm.com","sourceware.org;\n spf=pass smtp.mailfrom=oss.qualcomm.com","server2.sourceware.org;\n arc=pass smtp.remote-ip=205.220.180.131"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fxWJv2Lm7z1yGt\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 07:25:49 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id E88864C900E3\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 21:25:47 +0000 (GMT)","from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com\n [205.220.180.131])\n by sourceware.org (Postfix) with ESMTPS id AE38D4BA2E04\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 21:25:16 +0000 (GMT)","from pps.filterd (m0279872.ppops.net [127.0.0.1])\n by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 63GF1wSq4027954\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 21:25:16 GMT","from mail-dy1-f198.google.com (mail-dy1-f198.google.com\n [74.125.82.198])\n by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dk227scnx-1\n (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 21:25:15 +0000 (GMT)","by mail-dy1-f198.google.com with SMTP id\n 5a478bee46e88-2c16233ee11so12268793eec.1\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 14:25:15 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org E88864C900E3","OpenDKIM Filter v2.11.0 sourceware.org AE38D4BA2E04"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org AE38D4BA2E04","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org AE38D4BA2E04","ARC-Seal":["i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1776374716; cv=pass;\n b=KdRipGEV1FSc60IJptVINvrnnSwsu7ojvu9JEQjbeBYpt2/J20sHv3lFIhUNM3UmXmmU/issAFJRnYSu1jAz6k2dRvUT4IB9wVq+2csy5m5SMLbxvqXwIMmg9LvVC8BQCru/EybAT2iQyKU500MWBF9SPPrwepgjeqsYqDhuTBE=","i=1; a=rsa-sha256; t=1776374715; cv=none;\n d=google.com; s=arc-20240605;\n b=KPVOaqUO0IlNGUuodZXoF0Skjzj7YaJXAky4pwLI3Bu0AwluxC5LiRi464qvANtASo\n 0mxGpDVsN4utWa8JMltpECKw0LNS0Pp1WxlZ+wl6uXCdB9FX/kSrEIyJEgvSY81Y74ne\n R2KmtcP0ffhK5WsdQDpeA/fjeBhzGydVrozGmd5szd9oNERLDCbc6HYP0EXz/1iKXlB2\n Ony3m3Y79Hl/Jv9lHhrXkenRWob/QAkIaw3y1qfbloKvc6SCW36U0eHmVya9XcwThjDu\n L48vJzEJJAXE6a+fHm9rdqqI9AlmgZ9pYe+9lqx/pOGCdgu17tcb7RWgoFcZ1Kpe8b2o\n EQ6g=="],"ARC-Message-Signature":["i=2; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776374716; c=relaxed/simple;\n bh=CfsobiRtRaP6gORQQoRY1FYgYKify+PPqIbALWS1xeI=;\n h=DKIM-Signature:DKIM-Signature:MIME-Version:From:Date:Message-ID:\n Subject:To;\n b=daq8ZLL+x09qHgOfcshX8KulM7CluCyAp/ByPMgi3PdsjKiNqGrYVDmXaWNtyVO1ui72BOYNDEvFxwqvcmIWDZIi7syxLhKml/uQoIlfNxYcO5+yB4n/CZYyaGvu1r1Amn8sSlT7yYoCHK3dtpw+chJ9VBcEt43rTtpBYPt3r2c=","i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;\n s=arc-20240605;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:dkim-signature;\n bh=mu6IEJAhX6rS1AA0wRLibBhrGRrDxiPZPKkxTwsl9Mk=;\n fh=6iYHMs1AWdlXsix1dekPdk3naIOb8QIZEI8h8UsuOtQ=;\n b=ZleMeJvIhEm3wCU9AhtmwnvHym0RVjWYrYAa98gPkQWPVVNLDNtDrTaatbShbFFYJD\n hwVD1NUwRoLFykB8SFYohspOAlkm/7PSHIwwbpsFcJahY/smm6jeCIH5cXQHObZaOhb9\n nXrEk17QsQc4gFrlJHTnirCAM5j3Cgzap+Qv7T5pI3wAKN+vwiivcuo9By8FVshQCNER\n 64KtFMWFequblYULYaH5Wl3mI2qMIDYFS62F0Eb5WbUtODMn1XZVAYSdEKzqkPhcEFhW\n Q3sFsnzKxcrYpajg48M208hIwKKNJg4YUumE/y7lucewQaXrLYbll8ZGqHQ50GN5clF1\n sp7w==; darn=gcc.gnu.org"],"ARC-Authentication-Results":["i=2; server2.sourceware.org","i=1; mx.google.com; arc=none"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n cc:content-transfer-encoding:content-type:date:from:in-reply-to\n :message-id:mime-version:references:subject:to; s=qcppdkim1; bh=\n mu6IEJAhX6rS1AA0wRLibBhrGRrDxiPZPKkxTwsl9Mk=; b=aKmE1CB18Eql8S1+\n JtWnDCls+tftPAHRHLJm2vkFxcjexpnOOQkQdvClDzKMTOHxmumvelgY/bOq983w\n HNqBjPENDBzT/rokhWDM6DcvhjLat5JsMZRX73pnxYXi6bV+FmLpsSpkPxmUPR8Z\n 6UiI9pBhlFSV/JAz8yoAr3NfrvXVH9thP+wfMmKV3gzqsjDUDO5SMGi3HUIcmviz\n EgNujqwQXPFyYahezEotTytHJPeTDl3H8zCUM3Q74ZU5CUiqdCU4sp78KJfJy/2s\n M/ZgDKVI30C+WRQtCZmovolKzgQogvTqC9wR5TYQW2nReIJ/SiFlM37HMfgFnwrl\n gpz4lA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=oss.qualcomm.com; s=google; t=1776374715; x=1776979515; darn=gcc.gnu.org;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:from:to:cc:subject:date\n :message-id:reply-to;\n bh=mu6IEJAhX6rS1AA0wRLibBhrGRrDxiPZPKkxTwsl9Mk=;\n b=Rt8QiAMit8DVutfQfpSKenno36ib1WbAIDqtO9/6Ee1Uy2cRm6hlf/JDVVPcKAwsAH\n SwHTbphkI/+BRKw3HqRu2cRbDkdB3fXmkBO+4K3HKTEJqjE37uWrGOkClB6EdOfGRSbb\n UFIHusUB5DVv25VgtqUdsTWOPJv6IG62lTDFrxdxeEOL5eTbi25fYpWTrACyCQS5oWVl\n ZuSztBn1P7XLTIl9khCLRt6UcZIf2g0cl+7Au9Q8i/K5TkU+qOKuOrrmmYevFzWoggN2\n HScTjLJuz53vzqZAqqb6ix00Joq42Up0vDfAexSYMgqMbxXXSm70owMQAwn3McWwlgmC\n ZCwQ=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776374715; x=1776979515;\n h=content-transfer-encoding:cc:to:subject:message-id:date:from\n :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=mu6IEJAhX6rS1AA0wRLibBhrGRrDxiPZPKkxTwsl9Mk=;\n b=Qtu8h0jzLSIyG+IQ/2ynkQ4MygInkfQdPDikQCKW4exXYcwJqBAfjmtxE9sJsppChm\n 8/vfuzBBK7u7HMVNEPfqMuSjhmIB4AjPuUpEwW/a4pise2NaNqfL4mMM5C2vOL72m9Fe\n pG/vfNGUMoDB1RirtJe6CHmcTEqLmnnxHCI3E1Wp3kMVPsIQEMwe7D6T12BrxMJb3uM3\n 8SO5PCjtYEwYHo9gqevdoSvtyLb54J24WryQqiprnYHvugaZh/yN2CSKNspZ6RtUBYuy\n vKvhdJLqpAJ+iAp5ToL67s7gsjK/54BNgaGbI7dj5cwql4XLz3uWauQuLOO2cWi/iYaD\n GHnw==","X-Gm-Message-State":"AOJu0YxBD+Bm7tkInAr44aKuuYWBC7kMqMn1mh/HSwxOFEV2PhCPxIsc\n uMDWu6WBBVlpZfwiIJbo1Kjgik7BD3j1/Z4Dgn0Y3qlGZajy+mvOj8s8JJFlM7cjOA/JwUrr9t/\n 2vGw00L/sHSa/OIDxE58Yu4TXsVtAnQLJfQkyjSCoOEm/eVnJWrkAU2ftg3YFjPqQNVmvIsS+7/\n +5Pdqv+cRB2Lm6RFUa9LMPxz7MEwTP6lDAN+8=","X-Gm-Gg":"AeBDieukQ4CjvMS0+OKyvGQ4QoMBVQYOd7MY0r766L05eop+dKh5blw9T/3gyX0ZTlO\n DJa3/xKf3KCUidynW9y0tbr7r/STpJNFZ7i1hiI2DKxDSDp7BRL1GvW32WKPlnv4nUxJTG3yoaK\n kQtiDJPmEyh5P45lv71lEtYa0tWnY3I3M0GDNDUQXLJe2u+DT2weZvCQYTM6wPpiU8Vd9F2Nw61\n JHTJPw9C/xc6eQ=","X-Received":["by 2002:a05:7301:168e:b0:2e2:d94d:6188 with SMTP id\n 5a478bee46e88-2e2e35842e7mr494490eec.7.1776374714550;\n Thu, 16 Apr 2026 14:25:14 -0700 (PDT)","by 2002:a05:7301:168e:b0:2e2:d94d:6188 with SMTP id\n 5a478bee46e88-2e2e35842e7mr494469eec.7.1776374713881; Thu, 16 Apr 2026\n 14:25:13 -0700 (PDT)"],"MIME-Version":"1.0","References":"<20260416122941.286122-1-daniel.barboza@oss.qualcomm.com>\n <CALvbMcCFQXXX=cfwb7fqPZ5-bF+X7nf7tgQ_xA_kNArBS63V1A@mail.gmail.com>\n <f87c6c59-8bb8-4c20-a0a9-c33164f8c53a@oss.qualcomm.com>\n <CALvbMcCXupBJsbH65c37J6t1c2RGdKr6+fz=kZfN+bQtnrs6XQ@mail.gmail.com>","In-Reply-To":"\n <CALvbMcCXupBJsbH65c37J6t1c2RGdKr6+fz=kZfN+bQtnrs6XQ@mail.gmail.com>","From":"Andrew Pinski <andrew.pinski@oss.qualcomm.com>","Date":"Thu, 16 Apr 2026 14:25:01 -0700","X-Gm-Features":"AQROBzAFZVdDgr7YiG-je3AHIiOdzf7LcHTLtE5zIRSFkmdVl7F7BTnN3gAwygQ","Message-ID":"\n <CALvbMcD8T8AgiNgaK4FPnCtOca7uGviFP=6LdfkLw-xQ1674KQ@mail.gmail.com>","Subject":"Re: [PATCH v3] match.pd: right shift compare canonicalization\n [PR124808]","To":"Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>","Cc":"gcc-patches@gcc.gnu.org, jeffrey.law@oss.qualcomm.com","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDE2MDIwMyBTYWx0ZWRfXz2pQaFejiseQ\n CYf2Z0EalHKtgxXSjY5HTbeI7WsCOU34TezSmwPnsktDlKISvDD3UYIsgZY0UaMAGoXmz7wklH1\n 0hbtQx06y/15WJicfVFDq8StXDAjw+dkUPLKD4r4oO+i0o9jR8Z8+iX7yjpX1mhkRbMAlKo5Opj\n dYl2srUAkM9aCFLbC4G3RCxp3fRWRB78btB8zJ4+IB4DA83meOMUTqhd71WCvtwnZj9p06B4gBV\n 5g/Cg8FkajMik1S6hle1Nyk7I+DzdeSFjAdNoYJbka/m2sFmmpwNjixmedhHoU2qZTqlwLzI/ok\n /Wu/AbD868DvNw54ljFe6j/8bHiJQVxh3vwGFdYBR4m9P0EUVgySJsUjj+D4yb3ZXJCBF4Pe8Y5\n Sb9lzFYQgsFrUkSIJLbLhc95x85NjQorGjSmGo+A5ijfMmcM28vKZ3fqYi7PlxYU4LL5QBaQzJy\n B02gnfZRuAHaTRQvbVA==","X-Proofpoint-ORIG-GUID":"dVjwcfFTQ6rmJKCWzxSbO6vgP0toiZTd","X-Proofpoint-GUID":"dVjwcfFTQ6rmJKCWzxSbO6vgP0toiZTd","X-Authority-Analysis":"v=2.4 cv=Iuoutr/g c=1 sm=1 tr=0 ts=69e153bb cx=c_pps\n a=wEP8DlPgTf/vqF+yE6f9lg==:117 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10\n a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22\n a=yx91gb_oNiZeI1HMLzn7:22 a=mDV3o1hIAAAA:8 a=EUspDBNiAAAA:8\n a=EkC59mOGShg2wNwOM-EA:9 a=QEXdDO2ut3YA:10 a=bBxd6f-gb0O0v-kibOvt:22","X-Proofpoint-Virus-Version":"vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-04-16_03,2026-04-16_03,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n bulkscore=0 adultscore=0 suspectscore=0 clxscore=1015 impostorscore=0\n malwarescore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 phishscore=0\n classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0\n reason=mlx scancount=1 engine=8.22.0-2604070000 definitions=main-2604160203","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}}]