)]}'
{
  "commit": "aaa0f6b1e87bc62ea15da6eab431af6dcebf6414",
  "tree": "a830a4fbcc26a0ca4ff2003de7ef3430fa27f038",
  "parents": [
    "5fa2866f2674d274034de150f669aee611c2d9fe"
  ],
  "author": {
    "name": "Kyrylo Tkachov",
    "email": "ktkachov@nvidia.com",
    "time": "Mon Aug 24 21:13:43 2026 +0200"
  },
  "committer": {
    "name": "Kyrylo Tkachov",
    "email": "ktkachov@nvidia.com",
    "time": "Fri Aug 28 16:04:42 2026 +0200"
  },
  "message": "match.pd: fold reductions of vector duplicates and repeats [PR127039]\n\nREDUC_MAX, REDUC_MIN, REDUC_AND and REDUC_IOR are idempotent.  A\nreduction of a nonempty duplicate vector with one of these operations is\nthe duplicated element:\n\n  v \u003d [vec_duplicate_expr] x;\n  res \u003d .REDUC_MAX (v);\n\nbecomes:\n\n  res \u003d x;\n\nFor example, the new SVE test contains:\n\n  int __GIMPLE ()\n  reduc_max (int x)\n  {\n    svint32_t v;\n    int res;\n\n    v \u003d svdup_s32 (x);\n    res \u003d .REDUC_MAX (v);\n    return res;\n  }\n\nWith -O2 -fgimple -march\u003darmv8.2-a+sve, the code changes from:\n\n  reduc_max:\n          mov     z31.s, w0\n          ptrue   p7.b, all\n          smaxv   s31, p7, z31.s\n          fmov    w0, s31\n          ret\n\nto:\n\n  reduc_max:\n          ret\n\nAn XOR reduction of a duplicate vector is zero when the number of lanes\nis even.  GCC permits variable-length vectors whose lane count has\nunknown parity, such as [1, 1].  Fold REDUC_XOR only when multiple_p\nproves that every possible lane count has the required parity.\n\nUse the same two paths as IFN_VEC_EXTRACT and IFN_VEC_SHL_INSERT.  Match\na nonconstant VEC_DUPLICATE_EXPR directly in match.pd.  Handle a\nVECTOR_CST in fold_const_reduction.\n\nStart constant folding with the explicitly encoded elements for both\nfixed-length and variable-length vectors.  A non-stepped encoding can be\nused for an idempotent reduction when every encoded element is guaranteed\nto be present.  For XOR, require the remaining encoded copies to cancel\nin pairs.  Process two periods of a duplicate encoding, or the foreground\nand background of a two-element-per-pattern encoding.  Use the exact\nelement count as a fallback when it is known.\n\nKeep REDUC_MAX and REDUC_MIN when a shortened reduction could return a\nsignaling NaN directly.  The full reduction can quiet the NaN and raise an\ninvalid-operation exception.\n\nThese folds also let the constant reduction in the PR 127039 rule\nsimplify for scalable constants.  The scalar result cannot match the\ninverse reduction-pair rule, so the nontermination cycle stays blocked.\n\nBootstrapped and tested on aarch64-none-linunx-gnu.\n\ngcc/ChangeLog:\n\n\tPR tree-optimization/127039\n\t* fold-const-call.cc (fold_const_reduction): Fold non-stepped constants\n\twhen the available lane-count information determines the result.\n\t* match.pd (reduction of a vector duplicate): New simplifications to\n\tthe duplicated element or zero.\n\ngcc/testsuite/ChangeLog:\n\n\tPR tree-optimization/127039\n\t* gcc.target/aarch64/sve/vec-reduc-dup-1.c: New test.\n\t* gcc.target/aarch64/sve/vec-reduc-pattern-1.c: New test.\n\t* gcc.target/aarch64/sve/vec-reduc-snan-1.c: New test.\n\t* gcc.target/aarch64/sve/vec-reduc-uniform-1.c: New test.\n\t* gcc.target/riscv/rvv/base/reduc-xor-uniform-1.c: New test.\n\nSigned-off-by: Kyrylo Tkachov \u003cktkachov@nvidia.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "c483b80e70456540a392bbc9ead68edbd07d06c2",
      "old_mode": 33188,
      "old_path": "gcc/fold-const-call.cc",
      "new_id": "342a65f42176ba7d5d09b3a8e953671bb09b4ce9",
      "new_mode": 33188,
      "new_path": "gcc/fold-const-call.cc"
    },
    {
      "type": "modify",
      "old_id": "c7841cab4599df2fb969e8fce8de9a9e5dabb6ac",
      "old_mode": 33188,
      "old_path": "gcc/match.pd",
      "new_id": "7f1cc1fb1d8e523ed6643843e542eaef0afca679",
      "new_mode": 33188,
      "new_path": "gcc/match.pd"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "9d5581d6811646a285b08688e20f0dfe42eef8f3",
      "new_mode": 33188,
      "new_path": "gcc/testsuite/gcc.target/aarch64/sve/vec-reduc-dup-1.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "59a3344f96b366488c993a5e92934586d1c13238",
      "new_mode": 33188,
      "new_path": "gcc/testsuite/gcc.target/aarch64/sve/vec-reduc-pattern-1.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "8781380510eeec5339194029b39ef07d5b5adb0d",
      "new_mode": 33188,
      "new_path": "gcc/testsuite/gcc.target/aarch64/sve/vec-reduc-snan-1.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "9830511b18dac1369416d663cd8aab6e79c2f0f6",
      "new_mode": 33188,
      "new_path": "gcc/testsuite/gcc.target/aarch64/sve/vec-reduc-uniform-1.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "54339490fd869ce5a328d94fc41982039549f6ea",
      "new_mode": 33188,
      "new_path": "gcc/testsuite/gcc.target/riscv/rvv/base/reduc-xor-uniform-1.c"
    }
  ]
}
