Closed lrita closed 5 years ago
I modify the asm code to this manually
.LCPI1_0:
.quad -9223372036854775808 # 0x8000000000000000
.quad -9223372036854775808 # 0x8000000000000000
.quad -9223372036854775808 # 0x8000000000000000
.quad -9223372036854775808 # 0x8000000000000000
.section .rodata,"a",@progbits
.LCPI1_1:
.long 0 # 0x0
.long 2 # 0x2
.long 4 # 0x4
.long 6 # 0x6
.zero 4
.zero 4
.zero 4
.zero 4
.text
.globl sample_max_avx2
and it works. Is it a correct way and a safely way?
Yes, that looks correct and should be ok.
@fwessels thanks for your reply. Does clang have a flag to enable/disable move the local variables to constant? I doesnot find a relevant flag and I does not know clang well .
@Irita Sorry for responding late to your question. Looks like your question got answered on https://stackoverflow.com/questions/50126786/how-to-prevent-clang-llvm-compile-local-variables-to-global . Did you get a chance to test the suggestion? Also, clang
has lots of flags that the result can be different with different combinations of flags. so, please try with the options given here https://clang.llvm.org/docs/ClangCommandLineReference.html
Hi @kannappanr,
If using -Os
instead of -O3
, the clang generate asm code without AVX2 instructions. It is not we wanted, we want the asm codes which is optimized for performance.
There are too many optimizations in -O3
, and which one affects the move local variables to constant
should be tested.
I do not find a quickly and easy way to do the test. Do I must generate the asm code by a hard way (llvm->opt->llc) ?
https://laure.gonnord.org/pro/teaching/CAP1718_ENSL/llvm_fernando.pdf
Hello @lrita , I am afraid you will need to do some testing on your own, clang has a ton of options and we only know the (bare) basics of it.
Going the opt / llc
way is certainly another option, but these tools have their own set of flags etc so you will need to study this.
I have a c code:
And compile it to asm by:
I found clang/llvm compile the local variables
int64_t max = 0x8000000000000000;
to global:Thus, when I use
c2goasm
to generate thegoasm
,it found
.quad -9223372036854775808 # 0x8000000000000000 .section .rodata,"a",@progbits .align 32
by getFirstLabelConstants, and generate a huge constant table by defineTable.Thanks.