<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/118273>118273</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Power Hardware] Codegen bug
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
IshwaraK
</td>
</tr>
</table>
<pre>
The clang compiler generates wrong assembly for the below C code in Power target. The function arguments are 'unsigned char' and doesn't appear to be honored in assembly code.
```
#include <stdio.h>
#include <stdlib.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 assembly output here, https://godbolt.org/z/MPE5qoKsv
In oraBar() function, the register r3 is loaded with 32 bits wide value using 'lwz' and then oraSetRegInfo() is called.
But in oraFoo(), the r3 is loaded with 'li 11, 255' (addi reg, 0, <signed immediate>) instruction, this means that the stored value in stack memory location doesn't guarantee to be unsigned 8 bits value. Thus, datatype of function args are not honored in this function call-chain and results into runtime wrong output.
The same C code is exercised in gcc and produces right assembly using 'lbz' instruction in oraBar() function. Please see the results here, https://godbolt.org/z/a6PYcxjPY
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU1v4zYQ_TX0ZRBDoixLPujgJGs0WBQw2l72FFDiWOKWIl1yaG_21xek_KFsFmg3ECaEOZz3ZjjzKLxXvUFsWPnIyueFCDRY17z44Syc-LxorXxr_hoQOi1MD50dj0qjgx4NOkHo4eys6UF4j2Or3-BgHdCA0KK2Z3iCzkoEZWBvz-iAhOuRlhAjHoLpSFkDwvVhREMehENgvAomkZLQDcIxXoEwEqRFbxiv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