[PATCH] D116941: [GlobalISel] Fix incorrect sign extension when combining G_INTTOPTR and G_PTR_ADD

Lucas Prates via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 13 03:27:44 PST 2022


pratlucas marked an inline comment as done.
pratlucas added inline comments.


================
Comment at: llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp:2040
+      NewCst = Cst.zextOrTrunc(DstTy.getSizeInBits());
+      NewCst += RHSCst->sextOrTrunc(DstTy.getSizeInBits());
       return true;
----------------
arsenm wrote:
> Why sext here?
Using sext here makes sure the pointer arithmetic works properly for negative offsets from `G_PTR_ADD`. This is also aligned with the behaviour of `IRTranslator`, which sign-extends the constant offset value (see https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp#L1516).
The extension here is not strictly necessary, as the `IRTranslator` already adjusts the constant size to match the pointer, but it should make things more future-proof without any harm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116941



More information about the llvm-commits mailing list