[PATCH] D150862: [RISCV][CodeGenPrepare] Select the optimal base offset for GEPs with large offset

luxufan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 21 02:15:51 PDT 2023


StephenFan added a comment.

I think we still resolved part of this problem instead of all of it. The reason is for

  define void @foo(ptr %dest) {
    %p1 = getelementptr i8, ptr %dest, i32 2048
    store i8 1, ptr %p1
    %p2 = getelementptr i8, ptr %dest, i32 2049
    store i8 1, ptr %p2
    %p3 = getelementptr i8, ptr %dest, i32 2050
    store i8 1, ptr %p3
    %p4 = getelementptr i8, ptr %dest, i32 2051
    store i8 1, ptr %p4
    ret void
  }

the extra `addi	a1, a0, 1` is produced by `2048` can not be represented in Int<12>. And this patch just resolved this kind of case. Consider that if the offset is `4194305`, the `addi` still exists since the instruction selector selects it to

  lui	a1, 1024
  addiw	a1, a1, 1

If you want to solve all of these kinds of cases, you need to repeat all the logic that selecting a large constant. So maybe handle it after instruction selection is a better way?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150862/new/

https://reviews.llvm.org/D150862



More information about the llvm-commits mailing list