Thanks Jeff. I've reached out to Roger to see if the fix would be better suited in CCP. If that isn't the right spot, I'll reach out to Aldy and Andrew about getting the fix in VRP/Ranger.
From: Jeff Law <jeffreya...@gmail.com> Sent: Sunday, August 22, 2021 8:11 PM To: Victor Tong <vit...@microsoft.com>; gcc-patches@gcc.gnu.org <gcc-patches@gcc.gnu.org>; pins...@gcc.gnu.org <pins...@gcc.gnu.org> Subject: [EXTERNAL] Re: [PATCH] Propagate get_nonzero_bits information in division [PR77980] On 7/26/2021 6:45 PM, Victor Tong via Gcc-patches wrote: > This change enables the "t1 != 0" check to be optimized away in this code: > > int x1 = 0; > unsigned int x2 = 1; > > int main () > { > int t1 = x1*(1/(x2+x2)); > if (t1 != 0) __builtin_abort(); > return 0; > } > > The change utilizes the VRP framework to propagate the get_nonzero_bits > information from the "x2+x2" expression to the "1/(x2+x2)" division > expression. Specifically, the framework knows that the least significant bit > of the "x2+x2" expression must be zero. > > The get_nonzero_bits information of the left hand side and right hand side of > expressions needed to be passed down to operator_div::wi_fold() in the VRP > framework. The majority of this change involves adding two additional > parameters to propagate this information. There are future opportunities to > use the non zero bit information to perform better optimizations in other > types of expressions. > > The changes were tested against x86_64-pc-linux-gnu and all tests in "make -k > check" passed. > > The original approach was to implement a match.pd pattern to support this but > the pattern wasn't being triggered. More context is available in: > https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fbugzilla%2Fshow_bug.cgi%3Fid%3D77980&data=04%7C01%7Cvitong%40microsoft.com%7C08dcd27e5482418d559708d965e3a826%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637652850726534114%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=S1WWWvuXwEIA20pmv%2Fn8kk6xlwv9VwsS%2BTl0jqEHf4w%3D&reserved=0 So you're going to want to sync with Aldy & Andrew as they're the experts on the Ranger design & implementation. This hits the Ranger API as well as design questions about how best to tie in the nonzero_bits capabilities. You might also want to reach out to Roger Sayle. He's been poking around in a closely related area, though more focused on the bitwise conditional constant propagation rather than Ranger/VRP. In fact, I just acked a patch of his that looks closely related. https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fpipermail%2Fgcc-patches%2F2021-August%2F577888.html&data=04%7C01%7Cvitong%40microsoft.com%7C08dcd27e5482418d559708d965e3a826%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637652850726534114%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=gn1L1exTW5TjdV8CDBDqB0Z5a4V7EP2tBM2uTF2ihck%3D&reserved=0 Jeff