[PATCH] D99033: GlobalISel: Constant fold G_PTR_ADD

Daniel Sanders via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 23 10:53:16 PDT 2021


dsanders added a comment.

In D99033#2645272 <https://reviews.llvm.org/D99033#2645272>, @aemerson wrote:

> Relaxing G_ADD semantics seems fine to me. Maybe we should still canonicalize on G_PTR_ADD during translation, and allow targets to legalize them into plain G_ADDs.

IRTranslator should definitely translate to G_PTR_ADD and G_PTR_ADD should not be considered equivalent to G_ADD. However for targets where pointers are just integers I see no harm in permitting G_ADD of pointers and targets custom-legalizing/lowering to that. It just shouldn't be something that happens without the targets actively choosing to do it.



================
Comment at: llvm/lib/CodeGen/GlobalISel/Utils.cpp:446
   case TargetOpcode::G_ADD:
+  case TargetOpcode::G_PTR_ADD:
     return C1 + C2;
----------------
I don't think we should add constant folding for G_PTR_ADD since it might not be an integer and might even be addrspace dependent behaviour. For integral pointers we should lower to G_ADD first, and then use G_ADD's constant folding.


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

https://reviews.llvm.org/D99033



More information about the llvm-commits mailing list