Files
cs420/examples/opt/pointer.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

34 lines
699 B
Plaintext

fun i32* @foo (i32*) {
init:
bid: b0
allocations:
block b0:
%b0:p0:i32*:a
ret %b0:p0:i32*
}
fun i32 @main () {
init:
bid: b0
allocations:
%l0:i32:a
block b0:
%b0:i0:unit = store 1:i32 %l0:i32*
%b0:i1:i32* = call @foo:[ret:i32* params:(i32*)]*(%l0:i32*)
%b0:i2:i32 = load %b0:i1:i32*
%b0:i3:i32 = add %b0:i2:i32 1:i32
%b0:i4:unit = store %b0:i3:i32 %b0:i1:i32*
%b0:i5:i32* = call @foo:[ret:i32* params:(i32*)]*(%l0:i32*)
%b0:i6:i32 = load %b0:i5:i32*
%b0:i7:i32 = add %b0:i6:i32 1:i32
%b0:i8:unit = store %b0:i7:i32 %b0:i5:i32*
%b0:i9:i32 = load %l0:i32*
%b0:i10:u1 = cmp eq %b0:i9:i32 3:i32
%b0:i11:i32 = typecast %b0:i10:u1 to i32
ret %b0:i11:i32
}