[PATCH] D107872: [SimplifyLibCalls] propagate tail flags on CallInsts

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 16 13:02:03 PST 2021


efriedma added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp:2440
+      assert(NewCI->isMustTailCall() &&
+             "replaced musttail call with non-musttail call");
+      (void)NewCI;
----------------
nickdesaulniers wrote:
> efriedma wrote:
> > nickdesaulniers wrote:
> > > efriedma wrote:
> > > > I don't understand this assertion.  There are two possibilities for simplification:
> > > > 
> > > > 1. We replace a call with some existing value.
> > > > 2. We replace a call with another new call.
> > > > 
> > > > For (1), this assertion doesn't make sense: we don't have a call.  For (2), we probably can't safely do the replacement in general; musttail has a bunch of restrictions, and the replacement call might not satisfy them.
> > > These asserts were added in response to https://reviews.llvm.org/D107872#3059254.  I think they do make sense, from the perspective of guarding against `musttail` calls being transformed.
> > > 
> > > If the old call is musttail, and the recommended replacement is not also musttail, assert that the suggestion is probably broken.
> > > 
> > > It is anomalous if a must tail call was simplified to a value. (1)
> > > 
> > > It is anomalous if a must tail call was simplified to a new call that's also not must tail.
> > > 
> > > Though if we just avoid the call to `Simplifier.optimizeCall` above if `CI` is must tail, then these asserts become impossible and can be removed.
> > I still think the assertion doesn't make sense.
> > 
> > In the "We replace a call with some existing value" case, consider, for example, memcpy.  We have an optimization that transforms memcpy->llvm.memcpy.  llvm.memcpy, doesn't have a return value, though, so we emit an llvm.memcpy, and return the value of the first operand. This operand may or may not be a call, and that call may or may not be a tail call.
> For the case you describe, `With` will not be the `CallInst` to `llvm.memcpy`; it will be the destination operand of the original call to `memcpy`, so the `dyn_cast` will return `nullptr`. Thus the assertion is not checked at runtime for the case you describe.
> 
> The assertion is only checked when we replace a `CallInst` with another `CallInst` (with the new `CallInst` being what's returned from the call to `LibCallSimplifier::optimizeCall`).
> 
> To me, the assertion is a guard for future changes to LibCallSimplifier to ensure `copyFlags` is done safely in a manner that is done throughout this diff.
> it will be the destination operand of the original call to memcpy

Yes.

> so the dyn_cast will return nullptr

I'm not following; is there some reason the destination can't be an instruction?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107872



More information about the llvm-commits mailing list