Constant propagation in llvm

时间:2016-04-25 09:25:57

标签: compiler-construction llvm compiler-optimization llvm-clang

I was checking llvm's constant propagation pass -sccp, with the following program

int a,b,c;
a=1;
b=2;
c=a+b;

I was expecting an output

  %a = alloca i32, align 4
  %b = alloca i32, align 4
  %c = alloca i32, align 4
  store i32 1, i32* %a, align 4
  store i32 2, i32* %b, align 4
  store i32 3, i32* %c, align 4 //constant propagation

But I am getting the following output

  %a = alloca i32, align 4
  %b = alloca i32, align 4
  %c = alloca i32, align 4
  store i32 1, i32* %a, align 4
  store i32 2, i32* %b, align 4
  %0 = load i32, i32* %a, align 4
  %1 = load i32, i32* %b, align 4
  %add = add nsw i32 %0, %1 //no constant propagation
  store i32 %add, i32* %c, align 4

What I am doing wrong here?

1 个答案:

答案 0 :(得分:1)

常量传播传递与许多其他传递一样,假设mem2reg首先在代码上使用。