RFR: 8331717: C2: Crash with SIGFPE Because Loop Predication Wrongly Hoists Division Requiring Zero Check [v2]

theoweidmannoracle duke at openjdk.org
Wed Dec 18 12:25:48 UTC 2024


On Tue, 17 Dec 2024 12:10:21 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:

> Maybe we should fix whatever is rewiring the DivI to the range check here?

The DivI is rewired and attached to the RangeCheck by IGVN in this case. Looking at the code 


int i1 = 0;

for (int i4 : iArr) {
    i4 = i1;
    try {
        iArr[0] = 1 / i4;  // 183 DivI
        i4 = iArr[2 / i4]; // 230 DivI
   } catch (ArithmeticException a_e) {
   }
}


and the resulting relevant nodes: 

![image](https://github.com/user-attachments/assets/43ca2671-7afe-4d19-9306-12be3837f490)

After several rounds of IGVN, we arrive at this state, where everything is still completely expected. 230 DivI is connected to its zero-check

![image](https://github.com/user-attachments/assets/ddde7e78-04b2-4850-a25f-38e8f392104d)


IGVN/Idealization will now see that the zero-check-if for 230 DivI is dominated by the uero-check-if for 183 DivI and therefore remove it from the graph. This seems a benign and useful transformation in general.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/22666#issuecomment-2551184815


More information about the hotspot-compiler-dev mailing list