[PATCH] D51194: [InstCombine] Fix issue in the simplification of pow() with nested exp{, 2}()

Evandro Menezes via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 23 15:57:59 PDT 2018


evandro created this revision.
evandro added reviewers: spatel, efriedma.
Herald added subscribers: llvm-commits, hiraditya.

Fix the issue of duplicating the call to `exp{,2}()` when it's nested in `pow()`, as exposed by https://reviews.llvm.org/rL340462.


Repository:
  rL LLVM

https://reviews.llvm.org/D51194

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


Index: llvm/test/Transforms/InstCombine/pow-exp.ll
===================================================================
--- llvm/test/Transforms/InstCombine/pow-exp.ll
+++ llvm/test/Transforms/InstCombine/pow-exp.ll
@@ -108,10 +108,8 @@
   ret double %pow
 }
 
-; FIXME: Should not result in two calls to exp2().
 define double @pow_exp2_libcall(double %x, double %y) {
 ; CHECK-LABEL: @pow_exp2_libcall(
-; CHECK-NEXT:    [[CALL:%.*]] = call fast double @exp2(double [[X:%.*]])
 ; CHECK-NEXT:    [[MUL:%.*]] = fmul fast double [[X]], [[Y:%.*]]
 ; CHECK-NEXT:    [[EXP2:%.*]] = call fast double @exp2(double [[MUL]])
 ; CHECK-NEXT:    ret double [[EXP2]]
Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1209,8 +1209,17 @@
     Function *CalleeFn = BaseFn->getCalledFunction();
     if (CalleeFn && TLI->getLibFunc(CalleeFn->getName(), LibFn) &&
         (LibFn == LibFunc_exp || LibFn == LibFunc_exp2) && TLI->has(LibFn)) {
+      Value *ExpFn;
+
+      // Create new exp{,2}() with the product as its argument.
       Value *FMul = B.CreateFMul(BaseFn->getArgOperand(0), Expo, "mul");
-      return emitUnaryFloatFnCall(FMul, CalleeFn->getName(), B, Attrs);
+      ExpFn = emitUnaryFloatFnCall(FMul, CalleeFn->getName(), B, Attrs);
+
+      // Erase original exp{,2}().
+      BaseFn->replaceAllUsesWith(ExpFn);
+      BaseFn->eraseFromParent();
+
+      return ExpFn;
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51194.162289.patch
Type: text/x-patch
Size: 1563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180823/296d3b6a/attachment.bin>


More information about the llvm-commits mailing list