[cfe-dev] disabling loop idiom recognizer in clang
Damjan Marion
damjan.marion at gmail.com
Thu Apr 28 16:08:28 PDT 2011
On Apr 29, 2011, at 12:59 AM, jahanian wrote:
>
> On Apr 28, 2011, at 3:49 PM, Damjan Marion wrote:
>
>>
>> On Apr 29, 2011, at 12:40 AM, Andrew Fish wrote:
>>
>>> On Apr 28, 2011, at 3:17 PM, Damjan Marion wrote:
>>>
>>>>
>>>> On Apr 29, 2011, at 12:15 AM, Chris Lattner wrote:
>>>>
>>>>>
>>>>> On Apr 28, 2011, at 3:09 PM, Damjan Marion wrote:
>>>>>
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> is there a way to disable loop idiom recognizer in clang?
>>>>>>
>>>>>> I have a problem with compiling early stage code for ARM architecture which should not be linked to external libraries but clang replaces loop with memset call in the code.
>>>
>>> If it is just the loop you care about make the pointer volatile.
>>>
>>>>>
>>>>> Yep, build with -fno-builtin or -ffreestanding.
>>>>
>>>> It doesn't work. According to gcc docs (which clang probably follows):
>>>> "GCC requires the freestanding environment provide memcpy, memmove, memset and memcmp."
>>>
>>>
>>> It works great, you just need your own copies of the functions. That is what we did for ARM EFI firmware, for gcc, clang, and RVCT. https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/ArmPkg/Library/CompilerIntrinsicsLib/Arm/. Sorry no makefiles as they get auto-generated from ../ CompilerIntrinsicsLib.inf. No floating point, but no external libraries means well no external libraries!
>>
>> In my case writing my own functions is slightly overkill for just avoiding clang to convert "for (i = 0; i <17; i++) c [i] = 0;" to memset. Must be a way to tell him not to mess with my loop :)
>
> Can you write it in a way that memset conversion logic does not recognize it; such as i =0; for (; i <17; i++) c [i] = 0;
It is too smart :)
# arm-none-eabi-objdump -S inflate-tramp.o | grep -B 2 -A 2 memset
b64: 858d0030 strhi r0, [sp, #48] ; 0x30
b68: e24b0064 sub r0, fp, #100 ; 0x64
b6c: ebfffffe bl 0 <memset>
i=0; for (; i < BMAX+1; i++) c [i] = 0;
More information about the cfe-dev
mailing list