3 ms·
I think common sub-expression elimination is a part of hoisting out of loops, which seems pretty important. I have seen Gcc dismantle one loop into two adjacen
by ncmncm 6y ago
I think common sub-expression elimination is a part of hoisting out of loops, which seems pretty important.
I have seen Gcc dismantle one loop into two adjacent loops, the first to pre-compute a table for the second loop. My jaw was on the floor.
- roca 6y agoCan you give an example where CSE/hoisting is necessary to make an abstraction zero-cost? I mean: give an example of a zero-cost abstraction that takes some hand-written code and packages it up nicely, and then show that the compiler can't compile it back down to the hand-written code without CSE/hoisting.
- fanf2 6y agoThe usual example is something like a safe array where the bounds are checked on every access. The bounds check is a common subexpression in code that accesses the array more than once. If the abstraction includes a safety check on access that doesn’t depend on the loop variable (eg if empty arrays are NULL) then that can be hoisted.