[LLVMdev] code generation removes duplicated instructions

D S Khudia daya.khudia at gmail.com
Tue Jul 5 18:31:53 PDT 2011


Hello,

I am duplicating few instructions in a basic block and splitting it. The
following is an example.

bb:                                               ; preds = %bb1
  %0 = load i32* %i, align 4
  %1 = getelementptr inbounds [100 x i32]* %a, i32 0, i32 %0
  store i32 0, i32* %1, align 4
  %2 = load i32* %i, align 4
  %3 = getelementptr inbounds [100 x i32]* %last_added, i32 0, i32 %2
  store i32 -1, i32* %3, align 4
  %4 = load i32* %i, align 4
  %5 = add nsw i32 %4, 1
  store i32 %5, i32* %i, align 4
  br label %bb1

==>

  %0 = load i32* %i, align 4
  %HV14_ = getelementptr inbounds [100 x i32]* %a, i32 0, i32 %0
  %1 = getelementptr inbounds [100 x i32]* %a, i32 0, i32 %0
  %HVCmp7 = icmp ne i32* %1, %HV14_
  br i1 %HVCmp7, label %relExit, label %bb.split

So that HV14_ is a new instruction and I am inserting a comparison to jump
to a newly created basic block. Somehow the code generation for arm removes
the duplicated instruction and cmp instruction in arm assembly looks as
follows.

cmp r0, r0

This defeats the purpose of doing the duplication in the first place. Does
anyone have any insight on this? Can anyone suggest some starting points to
debug this?


Thanks a lot.
Daya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110705/20469a36/attachment.html>


More information about the llvm-dev mailing list