gcc2011
2013-Nov-17 12:07 UTC
[LLVMdev] A question about Greedy Register Allocator's reload instruction.
Hi all, I'm very instresting in LLVM, and trying to port a dsp target on LLVM now. I found that, the Greddy Register Allocator will generate a reload instrucion just between the function call and ADJCALLSTACKUP instruction. If the reload instruction is transfered to be a load instruction finally, which uses the SP register as an operand, and the target uses the ADJCALLSTACKUP instruction to adjust the SP register's value, will the reload instruction get a bad SP register value? Let me use MBlaze to explain that: compile option: clang -target mblaze -O2 -S -mllvm -unroll-threshold=1024 -mllvm -unroll-allow-partial demo.c -o demo.s -mllvm -print-after-all The IR after Virtual Register Rewriter whill show this situation as below: " BRLID R15, ga at printf, %R3<imp_def,dead>, %R4<imp_def,dead>, %R5<imp_def,dead>... %R4<def>=LWI <fi#5>,0 ADJCALLSTACKUP 68, 0, %R1 <imp_def>, %R1<imp_def> " The instruction " %R4<def>=LWI <fi#5>,0" loads value from the stack, and it will use SP register as an operand. But the SP may need to be adjusted int the ADJCALLSTACKUP instruction(MBlaze will not do that), is it a problem? Or I get the wrong understanding? The demo code has no actual meaning. demo.c: extern float b[10][10]; extern void do_nothing(float a, float b); void fun() { register int i, j; register float f1, f2, f3, f4, f5, f6, f7, f8; float a[10][10]; float(int i = 0; i < 10; i++) { float(int j = 0; j < 10; j++) { f1 = a[i][j]; f2 = b[i][j]; f3 = f1 + f2; f4 = f3 * f3; f5 = f4 - f3; f6 = f4 + f3; f7 = f5 + f6; f8 = f6 + f7; do_nothing(f1, f2); } } float(int i = 0; i < 10; i++) { float(int j = 0; j < 10; j++) { printf("%f %f %f %f %f %f %f %f \n", f3, f4, f5, f6, f7, f8, a[i][j], b[i][j]); } } } Thank you very much! GooKe. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131117/9ad11277/attachment.html>
Arsen Hakobyan
2015-Feb-17 13:17 UTC
[LLVMdev] A question about Greedy Register Allocator's reload instruction.
Seems I am in a similar situation (if I don't misunderstood the question, otherwise I will create a separate thread) I got the following assembly code where I assume that stack adjustment was done incorrectly: .proc_beg func func: .stack 1 // BB#0: // %entry add %sp, $-1, %sp mov $0, 0[%sp] ... rtnsr add %sp, $1, %sp .proc_end func .proc_beg main main: .stack_init %sp .stack 3 // BB#0: // %entry add %sp, $-3, %sp mov $32, 1[%sp] mov $23, 0[%sp] mov 1[%sp], %R0 mov 0[%sp], %R1 jmp func mov %R0, g1 mov 1[%sp], %R0 jmp func mov 0[%sp], %R1 ////<<< Here I assume that the 0[%sp] has been changed during the first call of func. that is why an incorrect value is passed as the parameter. mov g1, %R1 mov %R0, g2 // printing %R1 // printing %R0 So I am not sure where to look for the issue. I am thinking that it could be just an optimization issue after the correct register allocation or stack adjustment, or may be this is connected with Pseudo hook instructions ADJCALLSTACKDOWN and ADJCALLSTACKUP :? I am using an -O3 optimization level. I would greatly appreciate any suggestion where to look for the issue. Thanks, Arsen -- View this message in context: http://llvm.1065342.n5.nabble.com/A-question-about-Greedy-Register-Allocator-s-reload-instruction-tp63488p77953.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Apparently Analagous Threads
- Improving the split heuristics for the Greedy Register Allocator
- Improving the split heuristics for the Greedy Register Allocator
- [LLVMdev] Stack alignment problem
- [LLVMdev] Stack alignment problem
- Changes to 'ADJCALLSTACK*' and 'callseq_*' between LLVM v4.0 and v5.0