era-compiler-llvm icon indicating copy to clipboard operation
era-compiler-llvm copied to clipboard

SP is used as a register operand of `add` instruction

Open atrosinenko opened this issue 1 year ago • 0 comments

When testing #584 I observed add instruction using sp as a regular register operand:

  add  r1, r0, sp

This was triggered by passing the following input to llc:

target datalayout = "E-p:256:256-i256:256:256-S32-a:256:256"
target triple = "eravm"

define i256 @call.onestack(i256 %size) nounwind {
  %p = alloca i256, i256 %size
  %1 = call i256 @many_args_with_ptr(ptr %p, i256 0, i256 0, i256 0, i256 0, i256 0, i256 0, i256 0, i256 0, i256 0, i256 0, i256 0, i256 0, i256 0, i256 0)
  ret i256 %1
}

declare i256 @many_args_with_ptr(ptr, i256, i256, i256, i256, i256, i256, i256, i256, i256, i256, i256, i256, i256, i256) nounwind

As of now, I cannot reproduce this on main branch as #584 fixes an assertion triggered by the same code, but passing -print-after-all option to llc shows that ISel generates COPY instructions between $sp and virtual register from the gr256 register class. These are later lowered to adds.

atrosinenko avatar May 31 '24 15:05 atrosinenko