[Bug target/54445] TLS array lookup with negative constant is not combined into a single instruction
adam at consulting dot net.nz
gcc-bugzilla@gcc.gnu.org
Sat Sep 1 03:00:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54445
--- Comment #1 from Adam Warner <adam at consulting dot net.nz> 2012-09-01 03:00:39 UTC ---
Another example:
$ cat negative_constant_not_combined_into_a_single_instruction_example_2.c
#include <stdint.h>
__thread uint8_t byte_array[100];
uint64_t lookup_with_positive_constant(int64_t offset1, int64_t offset2) {
return *((uint64_t *) (byte_array + 8*offset1 + offset2 + 1));
}
uint64_t lookup_with_negative_constant(int64_t offset1, int64_t offset2) {
return *((uint64_t *) (byte_array + 8*offset1 + offset2 - 1));
}
int main(void) {
return 0;
}
$ gcc -O3 -std=gnu11 -pthread
negative_constant_not_combined_into_a_single_instruction_example_2.c && objdump
-d -m i386:x86-64:intel a.out |less
0000000000400540 <lookup_with_positive_constant>:
400540: 64 48 8b 84 fe 9d ff mov rax,QWORD PTR
fs:[rsi+rdi*8-0x63]
400547: ff ff
400549: c3 ret
0000000000400550 <lookup_with_negative_constant>:
400550: 64 48 8b 14 25 00 00 mov rdx,QWORD PTR fs:0x0
400557: 00 00
400559: 48 8d 04 fe lea rax,[rsi+rdi*8]
40055d: 48 81 c2 9c ff ff ff add rdx,0xffffffffffffff9c
400564: 48 8b 44 02 ff mov rax,QWORD PTR [rdx+rax*1-0x1]
400569: c3 ret
The memory load expands into four instructions when subtracting 1 from the byte
offset instead of adding 1.
More information about the Gcc-bugs
mailing list