On Thu May 18 20:32:04 2023 +0000, Ethan Lee wrote:
If I'm understanding correctly, the folding pass makes a temporary node that the fold functions write into - the fold function can either successfully inline an op into a constant that can replace the op node, or it can't and the temporary node is discarded, leaving the original node list alone. It sounds like the intended change to the current revision is to always assign the full constant value even if it turns out to be invalid - that is, the caller can either listen to the return value and discard the dst node, or use it at their own risk... does that make sense?
No, I don't think the caller gets to decide anything. The optimizing pass can either decide to alter the instruction stream (if it thinks there is some optimization to be done) or leave it unchanged. In the first case it returns `true`, in the second `false`. The caller will receive whatever stream the pass decides to leave.
In this case, however, I don't think there is any question about whether to touch or not the instruction stream. We definitely want to fold the absolute value operation, since it's pretty clear that for the native compiler `abs(INT_MIN) == INT_MIN`. The only care we have to use is to never call `abs(INT_MIN)` in C, because that's UB. If you use the statement I provided above that should never happen and everything is fine.