[LLVMdev] Strange code generation issue

Dibyendu Majumdar mobile at majumdar.org.uk
Sat Aug 1 09:36:20 PDT 2015


On 1 August 2015 at 15:37, Dibyendu Majumdar <mobile at majumdar.org.uk> wrote:
> Hi,
>
> I am using the LLVM release_37 branch and have a strange issue.
>
> Please see the two IR outputs I have saved below:
>
> https://github.com/dibyendumajumdar/ravi/tree/master/ravi-tests/comp_issue
>
> The original.ll is the code I am generating.
> The aftercompiling.ll is the output from LLVM with opt level 0.
>
> The issue is that LLVM is deciding to remove the blocks with labels
> updatei and updatei.64 (lines 433 and 454 in original.ll) for some
> reason that I cannot fathom. This is then causing the program to
> misbehave.
>
> I will check if the same issue occurs in LLVM 3.6.
>

I seem to get the same issue in 3.6.2.

The issue appears to be in the following area:

Original code:

forloop34_: ; preds = %forbody27_, %forbody21_
%200 = load i64, i64* %iidx53, !tbaa !17
%next.idx = add nsw i64 1, %200
store i64 %next.idx, i64* %iidx53, !tbaa !17
%201 = load i64, i64* %ilimit52, !tbaa !17
%idx.gt.limit = icmp sgt i64 %next.idx, %201
br i1 %idx.gt.limit, label %exit_iforloop, label %updatei

updatei: ; preds = %forloop34_
%202 = load %struct.TValue*, %struct.TValue** %base, !tbaa !14
%203 = getelementptr inbounds %struct.TValue, %struct.TValue* %202, i32 12
%204 = load i64, i64* %iidx53, !tbaa !17
%205 = bitcast %struct.TValue* %203 to i64*
store i64 %204, i64* %205, !tbaa !18
%dest.tt61 = getelementptr inbounds %struct.TValue, %struct.TValue*
%203, i32 0, i32 1
store i32 19, i32* %dest.tt61, !tbaa !15
br label %forbody27_


Transformed code:

forloop34_: ; preds = %forbody27_, %forbody21_
%208 = load i64, i64* %iidx53, !tbaa !17
%next.idx = add nsw i64 1, %208
store i64 %next.idx, i64* %iidx53, !tbaa !17
%209 = load i64, i64* %ilimit52, !tbaa !17
%idx.gt.limit = icmp sgt i64 %next.idx, %209
br i1 %idx.gt.limit, label %forloop35_, label %forbody27_

forbody21_:                                       ; preds = %forloop35_
  %sunkaddr137 = ptrtoint %struct.CallInfo* %0 to i64
  %sunkaddr138 = add i64 %sunkaddr137, 32
  %sunkaddr139 = inttoptr i64 %sunkaddr138 to %struct.TValue**
  %104 = load %struct.TValue*, %struct.TValue** %sunkaddr139, !tbaa !14
  %105 = getelementptr inbounds %struct.TValue, %struct.TValue* %104, i32 8
  %106 = load i64, i64* %iidx, !tbaa !17
  %107 = bitcast %struct.TValue* %105 to i64*
  store i64 %106, i64* %107, !tbaa !18
  %dest.tt65 = getelementptr inbounds %struct.TValue, %struct.TValue*
%105, i32 0, i32 1
  store i32 19, i32* %dest.tt65, !tbaa !15


So in the transformed code %105 should be %203 in the original code ...

Regards



More information about the llvm-dev mailing list