Add constant folding#51
Conversation
3569789 to
6e5c6a9
Compare
| } | ||
|
|
||
| /* Sign-extend an integer from w bits to int64_t. */ | ||
| static int64_t sign_extend(int64_t val, int w) |
There was a problem hiding this comment.
I think theres some undefined behaviour here for c99. I think it should be 1ULL in both
| default: return 0; | ||
| } | ||
|
|
||
| r = mask_to_width(r, rw); |
There was a problem hiding this comment.
If a is a negative, left shifting it is undefined behaviour in c99. Needs r = (int64_t)((uint64_t)a << (b & (sw - 1)))
There was a problem hiding this comment.
I think but happy to discuss other approaches
|
Two more things: BIR_SDIV / BIR_SREM (the BIR_FPTRUNC ( Everything else looks great. No dynamic allocation, deterministic single-pass, correct SSA traversal. Clean work. Edit: oh, my manners, thank you again! |
|
thank YOU for the feedback and quick response! love BarraCUDA |
Zaneham
left a comment
There was a problem hiding this comment.
Approved, requested changes have been made, thanks again!
This PR adds single-pass constant folding for BIR. Folds constant expressions at compile time so 3+4 becomes 7 in the IR instead of an actual add instruction. Handles ints, floats, comparisons, casts, select. One forward pass, DCE cleans up after.