[all-commits] [llvm/llvm-project] a89a65: [TailCallElim] Drop poison-generating flags on rea...

Justin Lebar via All-commits all-commits at lists.llvm.org
Sun May 31 09:19:58 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a89a6596129cbfdf788c5d0af0d4e071708afcf4
      https://github.com/llvm/llvm-project/commit/a89a6596129cbfdf788c5d0af0d4e071708afcf4
  Author: Justin Lebar <justin.lebar at gmail.com>
  Date:   2026-05-31 (Sun, 31 May 2026)

  Changed paths:
    M llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
    M llvm/test/Transforms/TailCallElim/accum_recursion.ll
    M llvm/test/Transforms/TailCallElim/dropping_debugloc_acc_rec_inst_rnew.ll

  Log Message:
  -----------
  [TailCallElim] Drop poison-generating flags on reassociated accumulators (#200624)

For example if you have recursion like

    int prod(n) {
      if (n == 0) return 1;
      return prod(n-1) * f(n)
    }

then logically this computes (((f(1) * f(2)) * f(3)) * f(4)) * ... f(n).

But TailCallElim reassociates this, computing instead
((f(n) * f(n-1)) * f(n-2)) * ...

If the operator (* in this case) had poison-generating flags like
nsw, those may not still apply after reassociation.  (For example,
suppose in this example f(1) returns 0 -- in that case the original
multiplication cannot overflow, but the new one still might.)

Fix this by clearing the poison-generating flags after reassociating.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list