Files
cs420/examples/opt/side_effect.ir
Jaewoo Kim 32283f2ed1 Update model solution.
- Stop calculating operands for & operators.
- Evaluate the lhs of compound operators only once.
- Add `side-effect.c` example.
2025-04-07 11:03:18 +00:00

30 lines
475 B
Plaintext

var i32 @g = 0
fun i32* @foo () {
init:
bid: b0
allocations:
block b0:
%b0:i0:i32 = load @g:i32*
%b0:i1:i32 = add %b0:i0:i32 10:i32
%b0:i2:unit = store %b0:i1:i32 @g:i32*
ret @g:i32*
}
fun i32 @main () {
init:
bid: b0
allocations:
block b0:
%b0:i0:i32* = call @foo:[ret:i32* params:()]*()
%b0:i1:i32 = load %b0:i0:i32*
%b0:i2:i32 = add %b0:i1:i32 1:i32
%b0:i3:unit = store %b0:i2:i32 %b0:i0:i32*
%b0:i4:i32 = load @g:i32*
ret %b0:i4:i32
}