llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Incorrect const loaded into reg while passing args

Open IshwaraK opened this issue 2 years ago • 3 comments

For the below trivial C code, the oraFoo() function is passing all const args as numeric zero at all optimization level other than -O0. Even though the args not used in callee, there is no benefits of loading reg with numeric ZERO rather than its actual value.

#include <stdio.h>

typedef unsigned char ub1;
void  oraSetRegInfo(ub1);

void __attribute__((noinline)) oraBar(ub1 var1, ub1 var2, ub1 var3, ub1 var4,
                    ub1 var5, ub1 var6, ub1 var7,
                    ub1 var8, ub1 var9)
{
    oraSetRegInfo(var9);
}

void __attribute__((noinline)) oraFoo() 
{
  ub1 var = 255;
  oraBar(10, 20, 30, 40, 50, 60, 70, 80, var);
}

Please see the example assembly code here, https://godbolt.org/z/Kcqz7Enen

IshwaraK avatar Dec 03 '24 11:12 IshwaraK

@llvm/issue-subscribers-backend-powerpc

Author: Ishwara Sharma (IshwaraK)

For the below trivial C code, the oraFoo() function is passing all const args as numeric zero at all optimization level other than -O0. Even though the args not used in callee, there is no benefits of loading reg with numeric ZERO rather than its actual value.
#include &lt;stdio.h&gt;

typedef unsigned char ub1;
void  oraSetRegInfo(ub1);

void __attribute__((noinline)) oraBar(ub1 var1, ub1 var2, ub1 var3, ub1 var4,
                    ub1 var5, ub1 var6, ub1 var7,
                    ub1 var8, ub1 var9)
{
    oraSetRegInfo(var9);
}

void __attribute__((noinline)) oraFoo() 
{
  ub1 var = 255;
  oraBar(10, 20, 30, 40, 50, 60, 70, 80, var);
}

Please see the example assembly code here, https://godbolt.org/z/Kcqz7Enen

llvmbot avatar Dec 03 '24 15:12 llvmbot

This is in no way specific to PowerPC. It is simply an artifact of the IR specifying those arguments as poison values. There are other targets that do the same thing with this code (armv7, RISC-V, etc.).

nemanjai avatar Dec 03 '24 17:12 nemanjai