[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 16:16:19 PDT 2022


Saldivarcher updated this revision to Diff 473366.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137454

Files:
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/test/Transforms/InstCombine/pow-to-sqrt.ll


Index: llvm/test/Transforms/InstCombine/pow-to-sqrt.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/pow-to-sqrt.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+; This is a check to assure the attributes of `pow` do
+; not get passed to sqrt.
+
+define void @pow_to_sqrt(double %x) {
+; CHECK-LABEL: @pow_to_sqrt(
+; CHECK-NEXT: [[SQRT:%.*]] = call afn double @sqrt(double [[X:%.*]])
+; CHECK-NEXT: ret void
+;
+  %call = call afn double @pow(double %x, double 1.5)
+  ret void
+}
+
+declare double @pow(double noundef, double noundef)
Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -2160,8 +2160,9 @@
         return nullptr;
       ExpoF = &ExpoI;
 
-      Sqrt = getSqrtCall(Base, Pow->getCalledFunction()->getAttributes(),
-                         Pow->doesNotAccessMemory(), M, B, TLI);
+      // Attributes are only meaningful on the original call
+      AttributeList Attrs;
+      Sqrt = getSqrtCall(Base, Attrs, Pow->doesNotAccessMemory(), M, B, TLI);
       if (!Sqrt)
         return nullptr;
     }


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


More information about the llvm-commits mailing list