Skip to content

Conversation

@a7ehuo
Copy link
Contributor

@a7ehuo a7ehuo commented Jan 14, 2026

Reject natural loops as idiom candidates if any catch handler block appears in the loop region (including nested blocks). Loops containing catch blocks are not suitable for CISC idiom transformations (e.g., MemSet/MemCpy) because the exception path alters the loop region’s CFG and prevents extraction/alignment of the required idiom region. This change avoids wasted idiom analysis on loops whose CFG contains exception-handler paths.

Related: #21417

Reject natural loops as idiom candidates if any catch handler block
appears in the loop region (including nested blocks). Loops containing
catch blocks are not suitable for CISC idiom transformations
(e.g., MemSet/MemCpy) because the exception path alters the loop
region’s CFG and prevents extraction/alignment of the required
idiom region. This change avoids wasted idiom analysis on loops
whose CFG contains exception-handler paths.

Related: eclipse-openj9#21417
Signed-off-by: Annabelle Huo <a7eh1ogh@gmail.com>
@a7ehuo
Copy link
Contributor Author

a7ehuo commented Jan 14, 2026

@hzongaro May I ask you to review this change? Thank you!

@jdmpapin fyi

@a7ehuo
Copy link
Contributor Author

a7ehuo commented Jan 14, 2026

Here are some more details on how createLoopCandidates treats different types of loops without and with this change.

Loop Types Baseline With this change
Loop Type 1 accept reject
Loop Type 2 Inner loop is accepted.
Outer loop is rejected because it doesn't have block structure.
Inner loop is rejected.
Outer loop is rejected because it doesn't have block structure.
Loop Type 3 Inner loop is accepted. 
Outer loop is rejected because it is not inner most loop.
Inner loop is accepted. 
Outer loop is rejected because it is not inner most loop.
Loop Type 4 Inner loop is accepted. 
Outer loop is rejected because it is not inner most loop.
Inner loop is rejected. 
Outer loop is rejected because it is not inner most loop.

Loop Type 1

        for (int i = 0; i < a.length; i++) {
            try {
                a[i] = v;
            } catch (ArrayIndexOutOfBoundsException e) {
                // swallow (intended unreachable)
                sink++;
            }
        }

Loop Type 2

       for (int r = 0; r < aa.length; r++) {
            byte[] a = aa[r];
            for (int i = 0; i < a.length; i++) {
                try {
                    a[i] = v;
                } catch (ArrayIndexOutOfBoundsException e) {
                    sink++;
                }
            }
        }

Loop Type 3

       for (int r = 0; r < aa.length; r++) {
            byte[] a = aa[r];
            try {
                for (int i = 0; i < a.length; i++) {
                    a[i] = v;
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                sink++;
            }
        }

Loop Type 4

       for (int r = 0; r < aa.length; r++) {
            byte[] a = aa[r];
            try {
                for (int i = 0; i < a.length; i++) {
                    try {
                        a[i] = v;
                    } catch (ArrayIndexOutOfBoundsException e) {
                        sink++;
                    }
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                sink++;
            }
        }

@a7ehuo a7ehuo requested a review from hzongaro January 14, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant