JDK-8264879 : Optimize out redundant ifs for constant test.
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 17
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2021-04-08
  • Updated: 2022-11-29
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Description
```
 public static int condgt(int a, int b) {
     if (b > 0) {
       if (b > -10) {                 // redundant test
         return 0xdd;
       }else {
         return 0xff;                // dead code
       }
     }else {
       return 0xee;
     }
   }
```

For the test case above, "b > -10" could be removed safely as it's always true.

So far c2 did related work for BoolTest::eq but remains some other cases like ne, le, ge, lt, gt.
Comments
Roland said that his fix for JDK-8275202 will probably solve this as well.
29-11-2022

Hi Tobias, Thanks for your attention! That's a good idea to remove those dead code by dominator. And I was thinking how about recording those type info in parsing-time[1] by CastNode, so that the following GVN could remove dead branch as well. In this way, there might be lots of CastNode in the graph but can be removed after LoopOpt if they were marked as 'range_check_dependency'. I'm not sure if it's valuable to keep those type info in such a long term GVN phase, perhaps some optimization would miss matched due to the new born CastNode, unless we have a way to uncast them, e.g.[2]. - Eric [1] https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/parse2.cpp#L1798 [2] https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/subnode.cpp#L98
03-06-2021

This looks related to JDK-8263252. [~rraghavan] has a prototype fix that might address this issue as well: https://github.com/openjdk/jdk/pull/2758/files/5cef73ad4b26a398f0ffab28a01a7f7799d19a6b
08-04-2021