[LLVMdev] How to Store variable allocation in Registers

Avinash Bole boleavinash at gmail.com
Mon May 11 04:08:54 PDT 2015


Hi Bruce!!

Im using "C" language.

As you said...,i tried using Global pointer..,but i still am not able to
get the Registers exactly as i wanted.

I found "-mem2reg" as a better alternative. But Problem is even though the
resulting Intermediate file( .ll ) is
good...,the final assembly file( .s) file is making a lot of DCE.

Im Posting an example :


*Original Intermediate file :*

define void @main() #0 {
  %a = alloca i32, align 4
  %b = alloca i32, align 4
  %c = alloca i32, align 4
  store i32 2, i32* %a, align 4
  store i32 3, i32* %b, align 4
  store i32 4, i32* %c, align 4
  %1 = load i32* %a, align 4
  %2 = add nsw i32 %1, 10
  store i32 %2, i32* %a, align 4
  %3 = load i32* %a, align 4
  %4 = load i32* %b, align 4
  %5 = add nsw i32 %3, %4
  store i32 %5, i32* %a, align 4
  store i32 5, i32* %a, align 4
  %6 = load i32* %b, align 4
  %7 = sub nsw i32 %6, 2
  store i32 %7, i32* %b, align 4
  %8 = load i32* %b, align 4
  %9 = load i32* %a, align 4
  %10 = sub nsw i32 %8, %9
  store i32 %10, i32* %b, align 4
  %11 = load i32* %c, align 4
  %12 = xor i32 %11, 4
  store i32 %12, i32* %c, align 4
  %13 = load i32* %c, align 4
  %14 = load i32* %c, align 4
  %15 = xor i32 %13, %14
  store i32 %15, i32* %c, align 4
  %16 = load i32* %a, align 4
  %17 = load i32* %b, align 4
  %18 = or i32 %16, %17
  store i32 %18, i32* %a, align 4
  %19 = load i32* %b, align 4
  %20 = and i32 %19, 2
  store i32 %20, i32* %b, align 4
  store i32 7, i32* %a, align 4
  %21 = load i32* %a, align 4
  %22 = or i32 %21, 2
  %23 = load i32* %b, align 4
  %24 = load i32* %c, align 4
  %25 = or i32 %23, %24
  %26 = and i32 %22, %25
  store i32 %26, i32* %b, align 4
  ret void
}


*After using "-mem2reg"*:

define void @main() #0 {
  %1 = add nsw i32 2, 10
  %2 = add nsw i32 %1, 3
  %3 = sub nsw i32 3, 2
  %4 = sub nsw i32 %3, 5
  %5 = xor i32 4, 4
  %6 = xor i32 %5, %5
  %7 = or i32 5, %4
  %8 = and i32 %4, 2
  %9 = or i32 7, 2
  %10 = or i32 %8, %6
  %11 = and i32 %9, %10
  ret void
}

*Assembly file:*

 Return;


As you can see...,all the code is eliminated as dead code...,now is there a
possibility to stop Dead code elimination?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150511/c182e0ff/attachment.html>


More information about the llvm-dev mailing list