<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/142968>142968</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Why can't "const xxx *restrict" be optimized?
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
lvyitianshi
</td>
</tr>
</table>
<pre>
Why can't "const xxx *restrict" be optimized?
I'm sorry because I can't write makedown.
This is c code:
__attribute__((malloc)) int *get();
void _interface0(int p);
void _interface1(const int *restrict p);
int entry() {
int *p = get();
_interface0(*p);
_interface1(p);
_interface0(*p);
_interface1(p);
_interface0(*p);
_interface1(p);
_interface0(*p);
_interface1(p);
_interface0(*p);
_interface1(p);
return 0;
}
This is command line:
clang -S -O3 main.c -ffreestanding
This is assemble code:
.def @feat.00;
.scl 3;
.type 0;
.endef
.globl @feat.00
.set @feat.00, 0
.file "main.c"
.def entry;
.scl 2;
.type 32;
.endef
.text
.globl entry # -- Begin function entry
.p2align 4
entry: # @entry
# %bb.0:
pushq %rsi
subq $32, %rsp
callq get
movq %rax, %rsi
movl (%rax), %ecx
callq _interface0
movq %rsi, %rcx
callq _interface1
movl (%rsi), %ecx
callq _interface0
movq %rsi, %rcx
callq _interface1
movl (%rsi), %ecx
callq _interface0
movq %rsi, %rcx
callq _interface1
movl (%rsi), %ecx
callq _interface0
movq %rsi, %rcx
callq _interface1
movl (%rsi), %ecx
callq _interface0
movq %rsi, %rcx
callq _interface1
xorl %eax, %eax
addq $32, %rsp
popq %rsi
retq
# -- End function
.addrsig
Why p can't be optimized into the registers?
Can someone tell me how to do it, I know "pure" does my thing, but it needs not to return void.
If no one realizes that this is a point that can be optimized, I hope someone will pay attention:)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsVkGPozgT_TXOpRTkFNCJDxzo7onUp-_wrbTHloEKeMfYjG06yfz6lYFkkuz0arW3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