On Wed, Jun 10, 2020 at 10:24:59AM +0200, Martin Liška wrote: > > > This doesn't look correct to me. > > > I'd think the first adjust_address should be > > > mem = adjust_address (mem, ptr_mode, offset); > > > which will give you a MEM with ptr_mode which has SavedFlagPtr(FakeStack) > > > address, i.e. *SavedFlagPtr(FakeStack). > > > Next, you want to load that into some temporary, so e.g. > > > rtx addr = gen_reg_rtx (ptr_mode); > > > emit_move_insn (addr, mem); > > > next you need to convert that ptr_mode to Pmode if needed, so something > > > like > > > addr = convert_memory_address (Pmode, addr); > > > and finally: > > > mem = gen_rtx_MEM (QImode, addr); > > > emit_move_insn (mem, const0_rtx); > > > Completely untested. > > > > This is not correct. With your suggestion I have: > > > > int foo(int index) > > { > > int a[100]; > > return a[index]; > > } > > > > $ diff -u before.s after.s > > --- before.s 2020-06-01 15:15:22.634337654 +0200 > > +++ after.s 2020-06-01 15:16:32.205711511 +0200 > > @@ -81,8 +81,7 @@ > > movq %rdi, 2147450920(%rax) > > movq %rsi, 2147450928(%rax) > > movq %rdi, 2147450936(%rax) > > - movq 504(%rbx), %rax > > - movb $0, (%rax) > > + movb $0, 504(%rbx) > > jmp .L3 > > .L2: > > movq $0, 2147450880(%rax) > > > > There's missing one level of de-reference. Looking at clang: > > > > movq %rsi, 2147450928(%rax) > > movq %rdi, 2147450936(%rax) > > movq 504(%rbx), %rax > > movb $0, (%rax) > > jmp .L3 > > .L2: > > > > It does the same as my patch. > > Jakub?
Even if so, just add that another level of indirection where it belongs, but as I said, what you posted didn't feel right. E.g. we just shouldn't reuse MEMs (even after adjusting them) from different indirection levels because we risk some attributes (alias set, MEM_EXPR, whatever else) will stay around from the different indirection level. Jakub