[LLVMdev] Strange code generation issue

Dibyendu Majumdar mobile at majumdar.org.uk
Sat Aug 1 09:54:14 PDT 2015


Found the issue - bug is in the original code I am generating.

Apologies for the noise.

Regards

On 1 August 2015 at 17:50, Dibyendu Majumdar <mobile at majumdar.org.uk> wrote:
> Correction below:
>
> On 1 August 2015 at 17:36, Dibyendu Majumdar <mobile at majumdar.org.uk> wrote:
>> 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_
>>
>
> forbody27_:                                       ; preds = %forloop34_
>   %sunkaddr134 = ptrtoint %struct.CallInfo* %0 to i64
>   %sunkaddr135 = add i64 %sunkaddr134, 32
>   %sunkaddr136 = inttoptr i64 %sunkaddr135 to %struct.TValue**
>   %141 = load %struct.TValue*, %struct.TValue** %sunkaddr136, !tbaa !14
>   %142 = getelementptr inbounds %struct.TValue, %struct.TValue* %141, i32 12
>   %143 = load i64, i64* %iidx53, !tbaa !17
>   %144 = bitcast %struct.TValue* %142 to i64*
>   store i64 %143, i64* %144, !tbaa !18
>   %dest.tt61 = getelementptr inbounds %struct.TValue, %struct.TValue*
> %142, i32 0, i32 1
>   store i32 19, i32* %dest.tt61, !tbaa !15
>
>
> So it seems correct as far as I can make out as presumably
> %sunkaddr136 is same as %base.
>
> Regards



More information about the llvm-dev mailing list