[flang-commits] [flang] [llvm] [LoopIdiom] Recognize naive popcount loop pattern (PR #172677)

Aashcharya Gorakh via flang-commits flang-commits at lists.llvm.org
Wed Dec 17 07:14:26 PST 2025


https://github.com/Aashcharya1 updated https://github.com/llvm/llvm-project/pull/172677

>From 9d9af3828ff0ff99466cf25b9d305528dcf0c5c6 Mon Sep 17 00:00:00 2001
From: Aashcharya1 <aashcharyagorakh at gmail.com>
Date: Wed, 10 Dec 2025 05:09:48 +0530
Subject: [PATCH 1/5] [flang][docs] Remove stale inline links to Intel and IBM
 compiler options

Remove all inline links to Intel and IBM compiler options from the comparison tables, as these links have become stale (Intel links redirect to generic pages, IBM links redirect to PDF-only pages).

Option names are preserved for readability. The Data sources section still contains links to the main documentation pages.

Details:

- Removed 43 Intel compiler option links
- Removed 35 IBM compiler option links
- Removed 2 stale links in notes section
- Updated documentation text accordingly

Fixes #171464
---
 flang/docs/OptionComparison.md | 162 ++++++++++++++++-----------------
 1 file changed, 81 insertions(+), 81 deletions(-)

diff --git a/flang/docs/OptionComparison.md b/flang/docs/OptionComparison.md
index 934750a07e9bb..78b54e2285ab7 100644
--- a/flang/docs/OptionComparison.md
+++ b/flang/docs/OptionComparison.md
@@ -37,9 +37,9 @@ Note that compilers may support language features without having an option for t
 eN
    </td>
    <td>std=<em>level</em> </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=210">qlanglvl</a>, <a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=257">qsaa</a>
+   <td>qlanglvl, qsaa
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-stand">stand level</a>
+   <td>stand level
    </td>
    <td>Mstandard
    </td>
@@ -55,33 +55,33 @@ eN
 <p>
 fall-intrinsics
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=297">qxlf77</a>,
+   <td>qxlf77,
 <p>
-<a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=299">qxlf90</a>,
+qxlf90,
 <p>
-<a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=301">qxlf2003</a>,
+qxlf2003,
 <p>
-<a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=305">qxfl2008</a>,
+qxfl2008,
 <p>
-<a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=245">qport</a>
+qport
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-f66">f66</a>,
+   <td>f66,
 <p>
-<a href="https://software.intel.com/node/a8bfa478-22d5-4000-b0ac-b881804a7611">f77rtl</a>,
+f77rtl,
 <p>
-<a href="https://software.intel.com/node/647820a0-fc53-4252-a858-46feb012a281">fpscomp</a>,
+fpscomp,
 <p>
-<a href="https://software.intel.com/node/e610682a-00fe-4881-9cf7-8eee08c5f2a2">Intconstant</a>,
+Intconstant,
 <p>
-<a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-standard-realloc-lhs">nostandard-realloc-lhs</a>,
+nostandard-realloc-lhs,
 <p>
-<a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-standard-semantics">standard-semantics</a>,
+standard-semantics,
 <p>
-<a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-assume">assume nostd_intent_in</a>,
+assume nostd_intent_in,
 <p>
-<a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-assume">assume nostd_value</a>,
+assume nostd_value,
 <p>
-<a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-assume">assume norealloc_lhs</a>
+assume norealloc_lhs
    </td>
    <td>Mallocatable=95|03
    </td>
@@ -126,13 +126,13 @@ f fixed
 <p>
 ffixed-form
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=179">qfree</a>,
+   <td>qfree,
 <p>
-<a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=169">qfixed</a>
+qfixed
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-fixed">fixed</a>,
+   <td>fixed,
 <p>
-<a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-free">free</a>
+free
    </td>
    <td>Mfree,
 <p>
@@ -152,9 +152,9 @@ Mfixed
 <p>
 ffree-line-length-n
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=169">qfixed=n</a>
+   <td>qfixed=n
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-extend-source">extend-source [size]</a>
+   <td>extend-source [size]
    </td>
    <td>Mextend
    </td>
@@ -172,11 +172,11 @@ fd-lines-as-comments
    </td>
    <td>D,
 <p>
-<a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=161">qdlines</a>,
+qdlines,
 <p>
-<a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=306">qxlines</a>
+qxlines
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-d-lines-qd-lines">d-lines</a>
+   <td>d-lines
    </td>
    <td>Mdlines
    </td>
@@ -190,7 +190,7 @@ fd-lines-as-comments
    </td>
    <td>N/A
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=153">qnocr</a>
+   <td>qnocr
    </td>
    <td>N/A
    </td>
@@ -206,11 +206,11 @@ fd-lines-as-comments
    </td>
    <td>N/A
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=282">qsuffix</a>
+   <td>qsuffix
    </td>
-   <td><a href="https://software.intel.com/node/84174680-3c7d-4225-9611-6083f496aa9b">extfor</a>,
+   <td>extfor,
 <p>
-<a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-tf">Tf filename</a>
+Tf filename
    </td>
    <td>N/A
    </td>
@@ -299,9 +299,9 @@ fd-lines-as-comments
    </td>
    <td>N/A
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=296">U</a>
+   <td>U
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-names">names=keyword</a>
+   <td>names=keyword
    </td>
    <td>Mupcase
    </td>
@@ -315,9 +315,9 @@ fd-lines-as-comments
    </td>
    <td>fbackslash
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=163">qescape</a>
+   <td>qescape
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-assume">assume bscc</a>
+   <td>assume bscc
    </td>
    <td>Mbackslash
    </td>
@@ -331,7 +331,7 @@ fd-lines-as-comments
    </td>
    <td>N/A
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=223">qmbcs</a>
+   <td>qmbcs
    </td>
    <td>N/A
    </td>
@@ -347,7 +347,7 @@ fd-lines-as-comments
    </td>
    <td>N/A
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=228">qnullterm</a>
+   <td>qnullterm
    </td>
    <td>N/A
    </td>
@@ -381,7 +381,7 @@ fd-lines-as-comments
    </td>
    <td>N/A
    </td>
-   <td><a href="https://software.intel.com/node/42e8ec08-64cc-44ba-a636-20ed50c682cd">altparam</a>
+   <td>altparam
    </td>
    <td>N?A
    </td>
@@ -420,11 +420,11 @@ fd-lines-as-comments
    </td>
    <td>N/A
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=113">1</a>,
+   <td>1,
 <p>
-<a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=231">qonetrip</a>
+qonetrip
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-f66">f66</a>
+   <td>f66
    </td>
    <td>Monetrip
    </td>
@@ -487,9 +487,9 @@ s default64
    </td>
    <td>fdefault-real-[8|10|16]
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=252">qrealsize=[4|8]</a>
+   <td>qrealsize=[4|8]
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-real-size">real-size [32|64|128]</a>
+   <td>real-size [32|64|128]
    </td>
    <td>r[4|8]
    </td>
@@ -507,7 +507,7 @@ fdefault-real-8
    </td>
    <td>N/A
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-double-size">double-size[64|128]</a>
+   <td>double-size[64|128]
    </td>
    <td>N/A
    </td>
@@ -521,7 +521,7 @@ fdefault-real-8
    </td>
    <td>N/A
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=161">qdpc</a>
+   <td>qdpc
    </td>
    <td>N/A
    </td>
@@ -537,7 +537,7 @@ fdefault-real-8
    </td>
    <td>freal-[4|8]-real[4|8|10|16]
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=144">qautodbl=size</a>
+   <td>qautodbl=size
    </td>
    <td>N/A
    </td>
@@ -555,9 +555,9 @@ Mr8intrinsics
    </td>
    <td>N/A
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=190">qieee</a>
+   <td>qieee
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-assume">assume std_minus0_rounding</a>
+   <td>assume std_minus0_rounding
    </td>
    <td>N/A
    </td>
@@ -573,7 +573,7 @@ Mr8intrinsics
    </td>
    <td>N/A
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-assume">assume minus0</a>
+   <td>assume minus0
    </td>
    <td>
    </td>
@@ -620,9 +620,9 @@ s default64
    </td>
    <td>fdefault-integer-8
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=202">qintsize=[2|4|8]</a>
+   <td>qintsize=[2|4|8]
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-integer-size">integer-size [32|64|128]</a>
+   <td>integer-size [32|64|128]
    </td>
    <td>I[2|4|8],
 <p>
@@ -690,9 +690,9 @@ fdefault-integer-8
    </td>
    <td>N/A
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=297">qxlf77 oldboz</a>
+   <td>qxlf77 oldboz
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-assume">assume old_boz</a>
+   <td>assume old_boz
    </td>
    <td>N/A
    </td>
@@ -708,7 +708,7 @@ fdefault-integer-8
    </td>
    <td>N/A
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-assume">assume old_logical_assign</a>
+   <td>assume old_logical_assign
    </td>
    <td>N/A
    </td>
@@ -781,7 +781,7 @@ fdefault-integer-8
    </td>
    <td>N/A
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=153">qctyplss</a>
+   <td>qctyplss
    </td>
    <td>N/A
    </td>
@@ -820,9 +820,9 @@ fdefault-integer-8
    </td>
    <td>fimplicit-none
    </td>
-   <td>u, <a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=291">qundef</a>
+   <td>u, qundef
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-warn">warn declarations</a>
+   <td>warn declarations
    </td>
    <td>Mdclchk
    </td>
@@ -852,7 +852,7 @@ fdefault-integer-8
    </td>
    <td>fcray-pointer
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024776&aid=1#page=432">Default (near equivalent)</a>
+   <td>Default (near equivalent)
    </td>
    <td><a href="https://www.intel.com/content/www/us/en/develop/documentation/fortran-compiler-oneapi-dev-guide-and-reference/top/language-reference/a-to-z-reference/o-to-p/pointer-integer.html">Default (near equivalent)</a>
    </td>
@@ -868,7 +868,7 @@ fdefault-integer-8
    </td>
    <td>N/A
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=201">qintlog</a>
+   <td>qintlog
    </td>
    <td>N/A
    </td>
@@ -884,9 +884,9 @@ fdefault-integer-8
    </td>
    <td>fdec-static
    </td>
-   <td>Default, see <a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024776&aid=1#page=393">IMPLICIT STATIC</a> and <a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024776&aid=1#page=393">IMPLICIT AUTOMATIC</a>
+   <td>Default, see IMPLICIT STATIC and IMPLICIT AUTOMATIC
    </td>
-   <td>Default, see <a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-automatic">AUTOMATIC</a> and <a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-static-1#408BC4E6-7AA7-4475-A280-205D34AE2E4F">STATIC</a>
+   <td>Default, see AUTOMATIC and STATIC
    </td>
    <td><a href="https://www.pgroup.com/doc/pgi15fortref.pdf#page=86">Default</a>
    </td>
@@ -900,11 +900,11 @@ fdefault-integer-8
    </td>
    <td>fno-automatic
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=258">qsave</a>
+   <td>qsave
    </td>
-   <td><a href="https://software.intel.com/node/3ed16417-6eed-4e09-9edd-4ae03e77c6cf">save</a>,
+   <td>save,
 <p>
-<a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-auto">noauto</a>
+noauto
    </td>
    <td>Mnorecursive,
 <p>
@@ -920,11 +920,11 @@ Msave
    </td>
    <td>frecursive
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=254">q recur</a>
+   <td>q recur
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-assume">assume recursion</a>,
+   <td>assume recursion,
 <p>
-<a href="https://software.intel.com/node/1c3820b4-42a1-48ea-887a-2cf39a41ce53">recursive</a>
+recursive
    </td>
    <td>Mrecursive
    </td>
@@ -965,7 +965,7 @@ Msave
    </td>
    <td>N/A
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-coarray-qcoarray">coarray[=keyword]</a>
+   <td>coarray[=keyword]
    </td>
    <td>N/A
    </td>
@@ -979,9 +979,9 @@ Msave
    </td>
    <td>N/A
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=142">qassert=contig</a>
+   <td>qassert=contig
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-assume">assume contiguous_pointer</a>
+   <td>assume contiguous_pointer
    </td>
    <td>N/A
    </td>
@@ -995,9 +995,9 @@ Msave
    </td>
    <td>frepack-arrays
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=142">qassert=contig</a>
+   <td>qassert=contig
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-assume">assume contiguous_assumed_shape</a>
+   <td>assume contiguous_assumed_shape
    </td>
    <td>N/A
    </td>
@@ -1053,21 +1053,21 @@ Msave
    </td>
    <td>fopenmp
    </td>
-   <td><a href="https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=285">qswapomp</a>
+   <td>qswapomp
    </td>
-   <td><a href="https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-qopenmp-qopenmp">qopenmp</a>,
+   <td>qopenmp,
 <p>
-<a href="https://software.intel.com/node/26d2aef3-9c68-4ef2-9241-bce168a48629">qopenmp-lib</a>,
+qopenmp-lib,
 <p>
-<a href="https://software.intel.com/node/f8d22e40-7ed0-4ec6-8e80-d4d27010ca8b">qopenmp-link</a>,
+qopenmp-link,
 <p>
-<a href="https://software.intel.com/node/2cc99a64-9605-44e2-b40a-1409ba459a62">qopenmp-offload</a>,
+qopenmp-offload,
 <p>
-<a href="https://software.intel.com/node/02ef8658-3e66-4634-8a11-68eec60322c1">qopenmp-simd</a>,
+qopenmp-simd,
 <p>
-<a href="https://software.intel.com/node/088272f2-5eae-42c2-a053-20f42022343d">qopenmp-stubs</a>,
+qopenmp-stubs,
 <p>
-<a href="https://software.intel.com/node/0ed8bee0-62b4-4266-8cbb-f25b585d4800">qopenmp-threadprivate</a>
+qopenmp-threadprivate
    </td>
    <td><a href="https://www.pgroup.com/resources/docs/19.1/x86/pgi-ref-guide/index.htm#mp">mp</a>,
 <p>
@@ -1242,7 +1242,7 @@ IBM Fortran's options allow the source line length to be specified with the opti
 
 
 *   **IBM:** IBM has two options that do the same thing: "-1" and "-qonetrip".
-*   **Intel:** Intel used to support a "-onetrip" option, but it has been removed.  Intel now supports a "-f66" option that ensures that DO loops are executed at least once in addition to [several other Fortran 66 semantic features](https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-f66#320D769C-7C41-4A84-AE0E-50A72296A838).
+*   **Intel:** Intel used to support a "-onetrip" option, but it has been removed.  Intel now supports a "-f66" option that ensures that DO loops are executed at least once in addition to several other Fortran 66 semantic features.
 
 **<a name="real"></a>REAL, DOUBLE PRECISION, and COMPLEX Data**
 
@@ -1264,7 +1264,7 @@ These size options affect the sizes of variables, literals, and intrinsic functi
 **Promote or demote REAL type sizes:** These options change the meaning of data types specified by declarations of the form REAL(KIND=_N_), except, perhaps for PGI.
 
 *   **GNU:** The allowable combinations are "-freal-4-real-8", "-freal-4-real-10", "-freal-4-real-16", "-freal-8-real-4", "-freal-8-real-10", and "-freal-8-real-16".
-*   **IBM:** The "-qautodbl" option  is documented [here](https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=144).
+*   **IBM:** The "-qautodbl" option controls automatic promotion of REAL types.
 *   **PGI:** The "-Mr8" option promotes REAL variables and constants to DOUBLE PRECISION variables and constants, respectively. DOUBLE PRECISION elements are 8 bytes in length.  The "-Mr8intrinsics" option promotes the intrinsics CMPLX and REAL as DCMPLX and DBLE, respectively.
 
 **<a name="integer"></a>INTEGER and LOGICAL Data**
@@ -1330,7 +1330,7 @@ Here's the list of compilers surveyed, hot linked to the source of data on it.
 *   PGI -- [Compiler Reference version 19.1](https://www.pgroup.com/resources/docs/19.1/x86/pgi-ref-guide/index.htm#cmdln-options-ref), [Fortran Reference Guide version 17](https://www.pgroup.com/doc/pgi17fortref.pdf)
 *   [Flang](https://github.com/flang-compiler/flang/wiki/Using-Flang) -- information from GitHub
 
-This document has been kept relatively small by providing links to much of the information about options rather than duplicating that information.  For IBM, Intel, and some PGI options, there are direct links.  But direct links were not possible for Cray, GNU and some PGI options.
+This document has been kept relatively small by providing links to much of the information about options rather than duplicating that information.  For some PGI options, there are direct links.  But direct links were not possible for Cray, GNU and some PGI options.
 
 Many compilers have options that can either be enabled or disabled.  Some compilers indicate this by the presence or absence of the letters "no" in the option name (IBM, Intel, and PGI) while Cray precedes many options with either "e" for enabled or "d" for disabled.  This document only includes the enabled version of the option specification.
 

>From cd495be70ff5436a6ddebefab333a73fe81068cc Mon Sep 17 00:00:00 2001
From: Aashcharya Gorakh <162886620+Aashcharya1 at users.noreply.github.com>
Date: Thu, 11 Dec 2025 00:52:25 +0530
Subject: [PATCH 2/5] Update flang/docs/OptionComparison.md

Co-authored-by: Tarun Prabhu <tarunprabhu at gmail.com>
---
 flang/docs/OptionComparison.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/docs/OptionComparison.md b/flang/docs/OptionComparison.md
index 4dc83e1b8a469..d9925e42109fd 100644
--- a/flang/docs/OptionComparison.md
+++ b/flang/docs/OptionComparison.md
@@ -1330,7 +1330,7 @@ Here's the list of compilers surveyed, hot linked to the source of data on it.
 *   PGI -- [Compiler Reference version 19.1](https://www.pgroup.com/resources/docs/19.1/x86/pgi-ref-guide/index.htm#cmdln-options-ref), [Fortran Reference Guide version 17](https://www.pgroup.com/doc/pgi17fortref.pdf)
 *   [Classic Flang](https://github.com/flang-compiler/flang/wiki/Using-Flang) -- information from GitHub
 
-This document has been kept relatively small by providing links to much of the information about options rather than duplicating that information.  For some PGI options, there are direct links.  But direct links were not possible for Cray, GNU and some PGI options.
+This document has been kept relatively small by providing links to much of the information about options rather than duplicating that information.  For some PGI options, there are direct links.  But direct links were not possible for the remaining PGI options and those of other compilers
 
 Many compilers have options that can either be enabled or disabled.  Some compilers indicate this by the presence or absence of the letters "no" in the option name (IBM, Intel, and PGI) while Cray precedes many options with either "e" for enabled or "d" for disabled.  This document only includes the enabled version of the option specification.
 

>From 97028a5a1cd7645c37e525eae0b02f2a657b1a86 Mon Sep 17 00:00:00 2001
From: Aashcharya1 <aashcharyagorakh at gmail.com>
Date: Thu, 11 Dec 2025 04:36:13 +0530
Subject: [PATCH 3/5] Address reviewer comments regarding broken links

---
 flang/docs/OptionComparison.md | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/flang/docs/OptionComparison.md b/flang/docs/OptionComparison.md
index 78b54e2285ab7..5cca980060141 100644
--- a/flang/docs/OptionComparison.md
+++ b/flang/docs/OptionComparison.md
@@ -840,13 +840,13 @@ fdefault-integer-8
    </td>
    <td>N/A
    </td>
-   <td><a href="https://www.pgroup.com/doc/pgi15fortref.pdf#page=86">default</a>
+   <td>default
    </td>
    <td>N/A
    </td>
   </tr>
   <tr>
-   <td>Enable <a href="https://support.hpe.com/hpesc/public/docDisplay?docId=a00113911en_us&docLocale=en_US&page=Types.html">Cray pointers</a>
+   <td>Enable Cray pointers
    </td>
    <td>default
    </td>
@@ -854,7 +854,7 @@ fdefault-integer-8
    </td>
    <td>Default (near equivalent)
    </td>
-   <td><a href="https://www.intel.com/content/www/us/en/develop/documentation/fortran-compiler-oneapi-dev-guide-and-reference/top/language-reference/a-to-z-reference/o-to-p/pointer-integer.html">Default (near equivalent)</a>
+   <td>Default (near equivalent)
    </td>
    <td>Mcray
    </td>
@@ -888,7 +888,7 @@ fdefault-integer-8
    </td>
    <td>Default, see AUTOMATIC and STATIC
    </td>
-   <td><a href="https://www.pgroup.com/doc/pgi15fortref.pdf#page=86">Default</a>
+   <td>Default
    </td>
    <td>N/A
    </td>
@@ -1033,7 +1033,7 @@ recursive
   <tr>
    <td>Enable OpenACC
    </td>
-   <td> <a href="https://pubs.cray.com/content/S-3901/8.7/cray-fortran-reference-manual/program-model-specific-options">h acc</a>
+   <td>h acc
    </td>
    <td>fopenacc
    </td>
@@ -1041,7 +1041,7 @@ recursive
    </td>
    <td>N/A
    </td>
-   <td><a href="https://www.pgroup.com/resources/docs/19.1/x86/pgi-ref-guide/index.htm#acc">acc</a>
+   <td>acc
    </td>
    <td>N/A
    </td>
@@ -1049,7 +1049,7 @@ recursive
   <tr>
    <td>Enable OpenMP
    </td>
-   <td> <a href="https://pubs.cray.com/content/S-3901/8.7/cray-fortran-reference-manual/program-model-specific-options">h omp</a>
+   <td>h omp
    </td>
    <td>fopenmp
    </td>
@@ -1069,7 +1069,7 @@ qopenmp-stubs,
 <p>
 qopenmp-threadprivate
    </td>
-   <td><a href="https://www.pgroup.com/resources/docs/19.1/x86/pgi-ref-guide/index.htm#mp">mp</a>,
+   <td>mp,
 <p>
 Mcuda
    </td>
@@ -1322,7 +1322,7 @@ Here's the list of compilers surveyed, hot linked to the source of data on it.
 
 
 *   [Cray Fortran Reference Manual version 8.7](https://pubs.cray.com/content/S-3901/8.7/cray-fortran-reference-manual/compiler-command-line-options)
-*   IBM  (XLF) version 14.1 -- [Compiler Referenc](https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=93)e, [Language Reference](https://www-01.ibm.com/support/docview.wss?uid=swg27024776&aid=1)
+*   IBM  (XLF) version 14.1 -- [Compiler Reference](https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=93), [Compiler Reference direct PDF](https://www.ibm.com/support/pages/system/files/support/swg/swgdocs.nsf/0/94c58d010e922f6d852579de00261d61/$FILE/compiler.pdf) [Language Reference](https://www-01.ibm.com/support/docview.wss?uid=swg27024776&aid=1), [Language Reference PDF](https://www.ibm.com/support/pages/system/files/support/swg/swgdocs.nsf/0/7e46ea600b6646d0852579dc00331978/$FILE/langref.pdf)
 *   [Intel Fortran version 19.0](https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-alphabetical-list-of-compiler-options)
 *   [GNU Fortran Compiler version 8.3.0](https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gfortran/Option-Summary.html)
 *   [NAG Fortran Release 6.2](https://www.nag.co.uk/nagware/np/r62_doc/manual/compiler_2_4.html)
@@ -1330,7 +1330,7 @@ Here's the list of compilers surveyed, hot linked to the source of data on it.
 *   PGI -- [Compiler Reference version 19.1](https://www.pgroup.com/resources/docs/19.1/x86/pgi-ref-guide/index.htm#cmdln-options-ref), [Fortran Reference Guide version 17](https://www.pgroup.com/doc/pgi17fortref.pdf)
 *   [Flang](https://github.com/flang-compiler/flang/wiki/Using-Flang) -- information from GitHub
 
-This document has been kept relatively small by providing links to much of the information about options rather than duplicating that information.  For some PGI options, there are direct links.  But direct links were not possible for Cray, GNU and some PGI options.
+This document has been kept relatively small by providing links to much of the information about options rather than duplicating that information.  However, many inline links to specific compiler options have been removed as they have become stale.  The Data sources section below provides links to the main documentation pages for each compiler.
 
 Many compilers have options that can either be enabled or disabled.  Some compilers indicate this by the presence or absence of the letters "no" in the option name (IBM, Intel, and PGI) while Cray precedes many options with either "e" for enabled or "d" for disabled.  This document only includes the enabled version of the option specification.
 

>From fbbbc327475124bb1686224f38ca6ea220e69fd6 Mon Sep 17 00:00:00 2001
From: Aashcharya1 <aashcharyagorakh at gmail.com>
Date: Thu, 11 Dec 2025 18:39:59 +0530
Subject: [PATCH 4/5] Fixed links to have final destination

---
 flang/docs/OptionComparison.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/docs/OptionComparison.md b/flang/docs/OptionComparison.md
index ef54fb65926dc..776a6df3f4c4d 100644
--- a/flang/docs/OptionComparison.md
+++ b/flang/docs/OptionComparison.md
@@ -1322,7 +1322,7 @@ Here's the list of compilers surveyed, hot linked to the source of data on it.
 
 
 *   [Cray Fortran Reference Manual version 8.7](https://pubs.cray.com/content/S-3901/8.7/cray-fortran-reference-manual/compiler-command-line-options)
-*   IBM  (XLF) version 14.1 -- [Compiler Reference](https://www-01.ibm.com/support/docview.wss?uid=swg27024803&aid=1#page=93), [Compiler Reference direct PDF](https://www.ibm.com/support/pages/system/files/support/swg/swgdocs.nsf/0/94c58d010e922f6d852579de00261d61/$FILE/compiler.pdf) [Language Reference](https://www-01.ibm.com/support/docview.wss?uid=swg27024776&aid=1), [Language Reference PDF](https://www.ibm.com/support/pages/system/files/support/swg/swgdocs.nsf/0/7e46ea600b6646d0852579dc00331978/$FILE/langref.pdf)
+*   IBM  (XLF) version 14.1 -- [Compiler Reference](https://www.ibm.com/support/pages/compiler-reference-xl-fortran-linux-v141#page=93), [Compiler Reference direct PDF](https://www.ibm.com/support/pages/system/files/support/swg/swgdocs.nsf/0/94c58d010e922f6d852579de00261d61/$FILE/compiler.pdf) [Language Reference](https://www.ibm.com/support/pages/language-reference-xl-fortran-linux-v141), [Language Reference direct PDF](https://www.ibm.com/support/pages/system/files/support/swg/swgdocs.nsf/0/7e46ea600b6646d0852579dc00331978/$FILE/langref.pdf)
 *   [Intel Fortran version 19.0](https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-alphabetical-list-of-compiler-options)
 *   [GNU Fortran Compiler version 8.3.0](https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gfortran/Option-Summary.html)
 *   [NAG Fortran Release 6.2](https://www.nag.co.uk/nagware/np/r62_doc/manual/compiler_2_4.html)

>From 6b93db41499520b3afa6821b372e7bb68781cd5b Mon Sep 17 00:00:00 2001
From: Aashcharya1 <aashcharyagorakh at gmail.com>
Date: Wed, 17 Dec 2025 20:23:35 +0530
Subject: [PATCH 5/5] [LoopIdiom] Recognize naive popcount loop pattern

---
 .../Transforms/Scalar/LoopIdiomRecognize.cpp  | 254 +++++++++++++++++-
 .../Transforms/LoopIdiom/naive-popcount.ll    |  31 +++
 2 files changed, 271 insertions(+), 14 deletions(-)
 create mode 100644 llvm/test/Transforms/LoopIdiom/naive-popcount.ll

diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
index 1730ec067c2cc..7c0c4ba05a175 100644
--- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -273,7 +273,7 @@ class LoopIdiomRecognize {
   bool insertFFSIfProfitable(Intrinsic::ID IntrinID, Value *InitX,
                              Instruction *DefX, PHINode *CntPhi,
                              Instruction *CntInst);
-  bool recognizeAndInsertFFS();  /// Find First Set: ctlz or cttz
+  bool recognizeAndInsertFFS(); /// Find First Set: ctlz or cttz
   bool recognizeShiftUntilLessThan();
   void transformLoopToCountable(Intrinsic::ID IntrinID, BasicBlock *PreCondBB,
                                 Instruction *CntInst, PHINode *CntPhi,
@@ -287,6 +287,8 @@ class LoopIdiomRecognize {
   bool recognizeAndInsertStrLen();
 
   /// @}
+
+  bool recognizeNaivePopcount(const SCEV *BECount);
 };
 } // end anonymous namespace
 
@@ -402,6 +404,10 @@ bool LoopIdiomRecognize::runOnCountableLoop() {
     if (auto Res = HashRecognize(*CurLoop, *SE).getResult())
       optimizeCRCLoop(*Res);
 
+  // Try to recognize and replace naive shift-and-mask popcount.
+  if (recognizeNaivePopcount(BECount))
+    return true;
+
   return MadeChange;
 }
 
@@ -650,7 +656,8 @@ bool LoopIdiomRecognize::processLoopStores(SmallVectorImpl<StoreInst *> &SL,
     const SCEVAddRecExpr *FirstStoreEv =
         cast<SCEVAddRecExpr>(SE->getSCEV(FirstStorePtr));
     APInt FirstStride = getStoreStride(FirstStoreEv);
-    unsigned FirstStoreSize = DL->getTypeStoreSize(SL[i]->getValueOperand()->getType());
+    unsigned FirstStoreSize =
+        DL->getTypeStoreSize(SL[i]->getValueOperand()->getType());
 
     // See if we can optimize just this store in isolation.
     if (FirstStride == FirstStoreSize || -FirstStride == FirstStoreSize) {
@@ -1194,8 +1201,7 @@ bool LoopIdiomRecognize::processLoopStridedStore(
     R << "Transformed loop-strided store in "
       << ore::NV("Function", TheStore->getFunction())
       << " function into a call to "
-      << ore::NV("NewFunction", NewCall->getCalledFunction())
-      << "() intrinsic";
+      << ore::NV("NewFunction", NewCall->getCalledFunction()) << "() intrinsic";
     if (!Stores.empty())
       R << ore::setExtraArgs();
     for (auto *I : Stores) {
@@ -1500,8 +1506,7 @@ bool LoopIdiomRecognize::processLoopStoreOfLoopLoad(
            << ore::NV("NewFunction", NewCall->getCalledFunction())
            << "() intrinsic from " << ore::NV("Inst", InstRemark)
            << " instruction in " << ore::NV("Function", TheStore->getFunction())
-           << " function"
-           << ore::setExtraArgs()
+           << " function" << ore::setExtraArgs()
            << ore::NV("FromBlock", TheStore->getParent()->getName())
            << ore::NV("ToBlock", Preheader->getName());
   });
@@ -2215,8 +2220,7 @@ static bool detectPopcountIdiom(Loop *CurLoop, BasicBlock *PreCondBB,
     ConstantInt *Dec = dyn_cast<ConstantInt>(SubOneOp->getOperand(1));
     if (!Dec ||
         !((SubOneOp->getOpcode() == Instruction::Sub && Dec->isOne()) ||
-          (SubOneOp->getOpcode() == Instruction::Add &&
-           Dec->isMinusOne()))) {
+          (SubOneOp->getOpcode() == Instruction::Add && Dec->isMinusOne()))) {
       return false;
     }
   }
@@ -2327,8 +2331,8 @@ static bool detectShiftUntilZeroIdiom(Loop *CurLoop, const DataLayout &DL,
   // step 2: detect instructions corresponding to "x.next = x >> 1 or x << 1"
   if (!DefX || !DefX->isShift())
     return false;
-  IntrinID = DefX->getOpcode() == Instruction::Shl ? Intrinsic::cttz :
-                                                     Intrinsic::ctlz;
+  IntrinID =
+      DefX->getOpcode() == Instruction::Shl ? Intrinsic::cttz : Intrinsic::ctlz;
   ConstantInt *Shft = dyn_cast<ConstantInt>(DefX->getOperand(1));
   if (!Shft || !Shft->isOne())
     return false;
@@ -2831,9 +2835,8 @@ void LoopIdiomRecognize::transformLoopToPopcount(BasicBlock *PreCondBB,
     TcPhi->insertBefore(Body->begin());
 
     Builder.SetInsertPoint(LbCond);
-    Instruction *TcDec = cast<Instruction>(
-        Builder.CreateSub(TcPhi, ConstantInt::get(Ty, 1),
-                          "tcdec", false, true));
+    Instruction *TcDec = cast<Instruction>(Builder.CreateSub(
+        TcPhi, ConstantInt::get(Ty, 1), "tcdec", false, true));
 
     TcPhi->addIncoming(TripCnt, PreHead);
     TcPhi->addIncoming(TcDec, Body);
@@ -3473,7 +3476,8 @@ bool LoopIdiomRecognize::recognizeShiftUntilZero() {
   // intrinsic we'll use are not cheap. Note that we are okay with *just*
   // making the loop countable, even if nothing else changes.
   IntrinsicCostAttributes Attrs(
-      IntrID, Ty, {PoisonValue::get(Ty), /*is_zero_poison=*/Builder.getFalse()});
+      IntrID, Ty,
+      {PoisonValue::get(Ty), /*is_zero_poison=*/Builder.getFalse()});
   InstructionCost Cost = TTI->getIntrinsicInstrCost(Attrs, CostKind);
   if (Cost > TargetTransformInfo::TCC_Basic) {
     LLVM_DEBUG(dbgs() << DEBUG_TYPE
@@ -3589,3 +3593,225 @@ bool LoopIdiomRecognize::recognizeShiftUntilZero() {
   ++NumShiftUntilZero;
   return MadeChange;
 }
+
+bool LoopIdiomRecognize::recognizeNaivePopcount(const SCEV *BECount) {
+  // Early exit: If trip count is already 0, loop is dead (already optimized)
+  if (BECount->isZero())
+    return false;
+
+  // 1. Basic Safety Checks
+  if (!CurLoop || CurLoop->getNumBackEdges() != 1 ||
+      CurLoop->getNumBlocks() != 1)
+    return false;
+
+  BasicBlock *Header = CurLoop->getHeader();
+  BasicBlock *Preheader = CurLoop->getLoopPreheader();
+  BasicBlock *ExitBB = CurLoop->getExitBlock();
+
+  if (!Header || !Preheader || !ExitBB)
+    return false;
+
+  // Ensure terminator is a conditional branch we can manipulate
+  BranchInst *TermBI = dyn_cast<BranchInst>(Header->getTerminator());
+  if (!TermBI || !TermBI->isConditional())
+    return false;
+
+  // 2. Safety Limit (avoid huge blocks)
+  unsigned InstCount = 0;
+  for (Instruction &I : *Header) {
+    if (InstCount++ > 50)
+      return false;
+    if (I.getType()->isVectorTy())
+      return false;
+  }
+
+  // 3. Match Canonical Induction Variable
+  PHINode *IndVar = CurLoop->getCanonicalInductionVariable();
+  Instruction *IVNext = nullptr;
+
+  if (!IndVar) {
+    for (PHINode &Phi : Header->phis()) {
+      ConstantInt *IVInit =
+          dyn_cast<ConstantInt>(Phi.getIncomingValueForBlock(Preheader));
+      if (!IVInit || !IVInit->isZero())
+        continue;
+
+      for (User *U : Phi.users()) {
+        if (Instruction *I = dyn_cast<Instruction>(U)) {
+          if (I->getParent() == Header && I->getOpcode() == Instruction::Add) {
+            Value *Op1 = I->getOperand(1);
+            if (ConstantInt *One = dyn_cast<ConstantInt>(Op1)) {
+              if (One->isOne() && I->getOperand(0) == &Phi) {
+                IndVar = Φ
+                IVNext = I;
+                break;
+              }
+            }
+          }
+        }
+      }
+      if (IndVar)
+        break;
+    }
+  } else {
+    for (User *U : IndVar->users()) {
+      if (Instruction *I = dyn_cast<Instruction>(U)) {
+        if (I->getParent() == Header && I->getOpcode() == Instruction::Add) {
+          if (I->getOperand(0) == IndVar &&
+              isa<ConstantInt>(I->getOperand(1)) &&
+              cast<ConstantInt>(I->getOperand(1))->isOne()) {
+            IVNext = I;
+            break;
+          }
+        }
+      }
+    }
+  }
+
+  if (!IndVar || !IVNext)
+    return false;
+
+  // 4. Match Accumulator and Bit Logic ((X >> i) & 1)
+  PHINode *AccPhi = nullptr;
+  Instruction *AddInst = nullptr;
+  Value *LoopVal = nullptr;
+
+  for (Instruction &Inst : *Header) {
+    if (Inst.getOpcode() != Instruction::Add)
+      continue;
+
+    PHINode *Phi = nullptr;
+    Value *Other = nullptr;
+    if (isa<PHINode>(Inst.getOperand(0))) {
+      Phi = cast<PHINode>(Inst.getOperand(0));
+      Other = Inst.getOperand(1);
+    } else if (isa<PHINode>(Inst.getOperand(1))) {
+      Phi = cast<PHINode>(Inst.getOperand(1));
+      Other = Inst.getOperand(0);
+    } else {
+      continue;
+    }
+
+    if (Phi->getParent() != Header)
+      continue;
+    ConstantInt *AccInit =
+        dyn_cast<ConstantInt>(Phi->getIncomingValueForBlock(Preheader));
+    if (!AccInit || !AccInit->isZero())
+      continue;
+
+    // Look through casts to find the And instruction
+    Value *AndInput = Other;
+    while (isa<CastInst>(AndInput))
+      AndInput = cast<CastInst>(AndInput)->getOperand(0);
+
+    Instruction *AndI = dyn_cast<Instruction>(AndInput);
+    if (!AndI || AndI->getOpcode() != Instruction::And)
+      continue;
+
+    ConstantInt *One = nullptr;
+    if ((One = dyn_cast<ConstantInt>(AndI->getOperand(1))) && One->isOne()) {
+    } else if ((One = dyn_cast<ConstantInt>(AndI->getOperand(0))) &&
+               One->isOne()) {
+    } else {
+      continue;
+    }
+
+    // Look through casts to find the Shift instruction
+    Value *ShiftInput = (AndI->getOperand(0) == One) ? AndI->getOperand(1)
+                                                     : AndI->getOperand(0);
+    while (isa<CastInst>(ShiftInput))
+      ShiftInput = cast<CastInst>(ShiftInput)->getOperand(0);
+
+    Instruction *ShrI = dyn_cast<Instruction>(ShiftInput);
+    if (!ShrI || (ShrI->getOpcode() != Instruction::LShr &&
+                  ShrI->getOpcode() != Instruction::AShr))
+      continue;
+
+    // Look through casts to find the shift amount
+    Value *ShAmt = ShrI->getOperand(1);
+    while (isa<CastInst>(ShAmt))
+      ShAmt = cast<CastInst>(ShAmt)->getOperand(0);
+    // The shift amount should be the induction variable itself
+    if (ShAmt != IndVar)
+      continue;
+
+    Value *X = ShrI->getOperand(0);
+    if (!CurLoop->isLoopInvariant(X))
+      continue;
+
+    LoopVal = X;
+    AccPhi = Phi;
+    AddInst = &Inst;
+    break;
+  }
+
+  if (!LoopVal || !AccPhi || !AddInst)
+    return false;
+
+  // 5. Verify Trip Count
+  unsigned BitWidth = LoopVal->getType()->getIntegerBitWidth();
+  const SCEVConstant *BECConst = dyn_cast<SCEVConstant>(BECount);
+  if (!BECConst)
+    return false;
+  if (BECConst->getAPInt().getZExtValue() + 1 != BitWidth)
+    return false;
+
+  // --- TRANSFORMATION ---
+
+  // 6. Insert Intrinsic in Preheader
+  IRBuilder<> Builder(Preheader->getTerminator());
+  CallInst *Ctpop =
+      createPopcntIntrinsic(Builder, LoopVal, AccPhi->getDebugLoc());
+
+  Value *FinalVal = Ctpop;
+  if (Ctpop->getType() != AccPhi->getType())
+    FinalVal = Builder.CreateTrunc(Ctpop, AccPhi->getType());
+
+  // 7. Replace uses by explicitly updating PHI nodes in ExitBB
+  // Don't use replaceUsesOutsideBlock on PHI nodes as it can cause hangs
+  ConstantInt *ExitCount = nullptr;
+  if (IndVar) {
+    uint64_t ExitVal = BECConst->getAPInt().getZExtValue() + 1;
+    auto *IndTy = cast<IntegerType>(IndVar->getType());
+    ExitCount = ConstantInt::get(IndTy, ExitVal);
+  }
+
+  // Update PHI nodes in ExitBB explicitly
+  SmallVector<PHINode *, 4> ExitPHIs;
+  for (PHINode &PN : ExitBB->phis()) {
+    int Idx = PN.getBasicBlockIndex(Header);
+    if (Idx == -1)
+      continue;
+    ExitPHIs.push_back(&PN);
+  }
+
+  for (PHINode *PN : ExitPHIs) {
+    int Idx = PN->getBasicBlockIndex(Header);
+    Value *IncomingVal = PN->getIncomingValue(Idx);
+
+    if (IncomingVal == AccPhi || IncomingVal == AddInst) {
+      PN->setIncomingValue(Idx, FinalVal);
+    } else if (ExitCount && (IncomingVal == IndVar || IncomingVal == IVNext)) {
+      PN->setIncomingValue(Idx, ExitCount);
+    }
+  }
+
+  // Replace uses outside the loop
+  // Use replaceUsesOutsideBlock which handles PHI nodes correctly
+  // We've already updated exit block PHI nodes explicitly above
+  AccPhi->replaceUsesOutsideBlock(FinalVal, Header);
+  AddInst->replaceUsesOutsideBlock(FinalVal, Header);
+
+  if (IndVar && ExitCount) {
+    IndVar->replaceUsesOutsideBlock(ExitCount, Header);
+    if (IVNext)
+      IVNext->replaceUsesOutsideBlock(ExitCount, Header);
+  }
+
+  // 8. Invalidate Analysis
+  SE->forgetLoop(CurLoop);
+
+  // LoopDeletion will detect the loop is dead and clean it up.
+
+  return true;
+}
diff --git a/llvm/test/Transforms/LoopIdiom/naive-popcount.ll b/llvm/test/Transforms/LoopIdiom/naive-popcount.ll
new file mode 100644
index 0000000000000..5a31929a4ab24
--- /dev/null
+++ b/llvm/test/Transforms/LoopIdiom/naive-popcount.ll
@@ -0,0 +1,31 @@
+; RUN: opt -passes=loop-idiom -S < %s | FileCheck %s
+; RUN: opt -passes='default<O2>,loop-idiom' -S < %s | FileCheck %s
+; RUN: opt -passes='default<O3>,loop-idiom' -S < %s | FileCheck %s
+
+; Verify that a canonical loop which accumulates bits using shift+mask is
+; converted into a single llvm.ctpop intrinsic call in all optimization modes.
+
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK-LABEL: @popcount_naive
+; CHECK-NOT: lshr
+; CHECK: {{.*}}call{{.*}}i64 @llvm.ctpop.i64
+; CHECK: ret i32
+define i32 @popcount_naive(i64 %x) {
+entry:
+  br label %for.body
+
+for.body:                                          ; preds = %for.body, %entry
+  %i = phi i64 [ 0, %entry ], [ %inc, %for.body ]
+  %acc = phi i32 [ 0, %entry ], [ %add, %for.body ]
+  %shr = lshr i64 %x, %i
+  %and = and i64 %shr, 1
+  %conv = trunc i64 %and to i32
+  %add = add i32 %acc, %conv
+  %inc = add i64 %i, 1
+  %cmp = icmp eq i64 %inc, 64
+  br i1 %cmp, label %exit, label %for.body
+
+exit:                                              ; preds = %for.body
+  ret i32 %add
+}



More information about the flang-commits mailing list