[LLVMdev] ldexp constant propagation

Ali Javadi aj14889 at yahoo.com
Tue Jun 25 10:02:51 PDT 2013


Hi,

I have the C program below,  which contains a mathematical expression.

C code:
======
void ControlledRotationPiMinus(int target, int control, int j)
{
	ControlledPhase(target,control,-PI/(2*pow(2,j)));
}

int main() {
	..
	int b = 3;
	for (int j=1; j < b; j++) 
		ControlledRotationPiMinus(target, control, j);
	..
}

Here is what I am doing: The function ControlledRotationPiMinus is called twice in main(), with values of j=1,2. I do procedure cloning (using CloneAndPruneFunctionInto) resulting in 2 copies of this function with the values of j set to a fixed number (1 and 2).
However the mathematical expression inside these copies fails to resolve to a fixed number and propagate. So for the first copy, with j=1, I get the following llvm code:

LLVM code:
=========

define void @ControlledRotationPiMinus_1(i32 %target, i32 %control, i32 %j) {
entry.:
  %exp2. = call double @ldexp(double 1.000000e+00, i32 1) nounwind
  %mul. = fmul double %exp2., 2.000000e+00
  %div. = fdiv double -3.141590e+00, %mul.
  call void @ControlledPhase(i32 %target, i32 %control, double %div.)
  ret void
}

I want to get a constant 3rd argument in the last call instruction (ControlledPhase), but it does not happen (I tried a lot of things including -constprop, -instcombine, etc.).
I found the problem to be with "ldexp". If I change my mathematical expression to something else (e.g. containing "sin", "sqrt", etc.) the constant propagation does happen. Any ideas on why this doesn't work for exponentials, and how I can fix it?

Thanks,
Ali



More information about the llvm-dev mailing list