willi19 / swpp202301-compiler-team6

MIT License
0 stars 0 forks source link

Some optimization ideas #34

Open willi19 opened 1 year ago

willi19 commented 1 year ago

1) Load store of global variable

%2 = load i64, i64 @C, align 8 %cmp2 = icmp ult i64 %2, %C_ br i1 %cmp2, label %for.body3, label %for.end6 br label %for.inc4 %3 = load i64, i64 @C, align 8 %shl5 = shl i64 %3, 1 store i64 %shl5, i64* @C, align 8 br label %for.cond1, !llvm.loop !8

void init(uint64t R, uint64t C) {

for (R = 1; R < R; R <<= 1) ; for (C = 1; C < C; C <<= 1) ; Yroot = malloc(3 sizeof(uint64_t)); ((uint64_t )Yroot) = NULL; *((uint64_t *)Yroot + 1) = NULL; ((uint64_t )Yroot + 2) = NULL; }

From this code, R is global variable and load and store are keep being used. However it is identical to load to local variable and then use it till branch, and store it right before branch. Will there be some flaw?

2) Global variable to stack Currently global variable is allocated to heap. I think we can load it to stack.

sharaelong commented 1 year ago
  1. Since it is sufficient to consider only single execution path (single core, single thread), so your idea seems okay.
  2. LGTM.