llvm optimizes with library functions

后端 未结 2 1414
没有蜡笔的小新
没有蜡笔的小新 2021-01-05 05:47

Starting with code like this

void lib_memset( unsigned char *dest, unsigned char c, unsigned int n)
{
    while(n--)
    {
        *dest=c;
        dest++;
          


        
2条回答
  •  误落风尘
    2021-01-05 06:33

    clang -Wall -m32 -emit-llvm -fno-builtin --target=arm-none-eabi -ffreestanding -c lib_memset.c -o lib_memset.bc
    opt -std-compile-opts -strip-debug -march=arm -mcpu=mpcore -mtriple=arm-none-eabi -disable-simplify-libcalls  lib_memset.bc -o lib_memset.opt.bc
    llc -march=arm -mcpu=mpcore -disable-simplify-libcalls -mtriple=arm-none-eabi  lib_memset.opt.bc -o lib_memset.opt.s
    llc -march=arm -mcpu=mpcore -disable-simplify-libcalls -mtriple=arm-none-eabi  lib_memset.bc -o lib_memset.s
    

    thanks to artless noise while adding -ffreestanding, I decided to re-read all the --help options for llc and opt, and found the -disable-simpilfy-libcalls is an option for both opt and llc, adding it to opt fixed the problem.

    lib_memset:
        cmp r2, #0
        bxeq    lr
    .LBB0_1:
        strb    r1, [r0], #1
        subs    r2, r2, #1
        bne .LBB0_1
        bx  lr
    

    I dont like answering my own question, can sit here for a bit so I can maybe find the answer next time or if the SO gods decide to leave it here that is fine...

提交回复
热议问题