[llvm] [InstCombine] Add log-pow simplification for FP exponent edge case. (PR #76641)

via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 30 16:04:27 PST 2023


================
@@ -2495,13 +2495,17 @@ Value *LibCallSimplifier::optimizeLog(CallInst *Log, IRBuilderBase &B) {
 
   // log(pow(x,y)) -> y*log(x)
   AttributeList NoAttrs;
-  if (ArgLb == PowLb || ArgID == Intrinsic::pow) {
+  if (ArgLb == PowLb || ArgID == Intrinsic::pow || ArgID == Intrinsic::powi) {
     Value *LogX =
         Log->doesNotAccessMemory()
             ? B.CreateCall(Intrinsic::getDeclaration(Mod, LogID, Ty),
                            Arg->getOperand(0), "log")
             : emitUnaryFloatFnCall(Arg->getOperand(0), TLI, LogNm, B, NoAttrs);
-    Value *MulY = B.CreateFMul(Arg->getArgOperand(1), LogX, "mul");
+    Value *Y = Arg->getArgOperand(1);
+    // If power is integer constant, convert to FP for FMul.
+    if (ConstantInt *C = dyn_cast<ConstantInt>(Y))
+      Y = ConstantFP::get(Ty, C->getSExtValue());
----------------
tanmaysachan wrote:

@dtcxzyw I did a standard sitofp initially, but that adds a casting instruction right? In the compiled asm there's an addition `scvtf` if using a non-constant cast.

I'll fix the illegal fmul, sorry about that.

https://github.com/llvm/llvm-project/pull/76641


More information about the llvm-commits mailing list