[PATCH] D137454: [InstCombine] Avoid passing pow attributes to sqrt

Miguel Saldivar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 4 11:44:11 PDT 2022


Saldivarcher created this revision.
Saldivarcher added a reviewer: spatel.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Saldivarcher requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

As described on this issue <https://github.com/llvm/llvm-project/issues/58475>, `instcombine` seems to be passing the attributes of `pow` to `sqrt`. This in turn causes an assertion to be hit later on.

Here is how to get the assertion:

  $ cat small.ll 
  define void @PR58475(double %x) {
    %call = call afn double @pow(double %x, double 1.5)
    ret void
  }
  
  declare double @pow(double noundef, double noundef)
  $ opt -instcombine small.ll -disable-output


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137454

Files:
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp


Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -2099,6 +2099,7 @@
   Module *M = Pow->getModule();
   bool AllowApprox = Pow->hasApproxFunc();
   bool Ignored;
+  AttributeList Attrs; // Attributes are only meaningful on the original call
 
   // Propagate the math semantics from the call to any created instructions.
   IRBuilderBase::FastMathFlagGuard Guard(B);
@@ -2160,8 +2161,7 @@
         return nullptr;
       ExpoF = &ExpoI;
 
-      Sqrt = getSqrtCall(Base, Pow->getCalledFunction()->getAttributes(),
-                         Pow->doesNotAccessMemory(), M, B, TLI);
+      Sqrt = getSqrtCall(Base, Attrs, Pow->doesNotAccessMemory(), M, B, TLI);
       if (!Sqrt)
         return nullptr;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137454.473302.patch
Type: text/x-patch
Size: 887 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221104/294a9234/attachment.bin>


More information about the llvm-commits mailing list