Skip to content

Conversation

@Ronxvier
Copy link

Moved constant folding logic from SimplifyLibCalls.cpp to ConstantFoldLibCall2
Meant to resolve #171877

Moved constant folding logic from SimplifyLibCalls.cpp to ConstantFoldLibCall2
@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms labels Dec 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 13, 2025

@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-llvm-transforms

Author: Ron Xavier (Ronxvier)

Changes

Moved constant folding logic from SimplifyLibCalls.cpp to ConstantFoldLibCall2
Meant to resolve #171877


Full diff: https://github.com/llvm/llvm-project/pull/172139.diff

2 Files Affected:

  • (modified) llvm/lib/Analysis/ConstantFolding.cpp (+12)
  • (modified) llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp (+2-12)
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index a9b51065a1d99..8a73c02bc363e 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -3241,6 +3241,18 @@ static Constant *ConstantFoldLibCall2(StringRef Name, Type *Ty,
     if (TLI->has(Func))
       return ConstantFoldBinaryFP(atan2, Op1V, Op2V, Ty);
     break;
+  case LibFunc_fdim:
+  case LibFunc_fdimf:
+  case LibFunc_fdiml:
+      if (TLI->has(Func)){
+    APFloat Difference = Op1V;
+    Difference.subtract(Op2V, RoundingMode::NearestTiesToEven);
+
+    APFloat MaxVal =
+        maximum(Difference, APFloat::getZero(Ty->getFltSemantics()));
+    return ConstantFP::get(Ty->getContext(), MaxVal);
+  }
+  break;
   }
 
   return nullptr;
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index c3537f544c432..55cd08b3de855 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -3201,18 +3201,8 @@ Value *LibCallSimplifier::optimizeFdim(CallInst *CI, IRBuilderBase &B) {
   if (isa<PoisonValue>(CI->getArgOperand(1)))
     return CI->getArgOperand(1);
 
-  const APFloat *X, *Y;
-  // Check if both values are constants
-  if (!match(CI->getArgOperand(0), m_APFloat(X)) ||
-      !match(CI->getArgOperand(1), m_APFloat(Y)))
-    return nullptr;
-
-  APFloat Difference = *X;
-  Difference.subtract(*Y, RoundingMode::NearestTiesToEven);
-
-  APFloat MaxVal =
-      maximum(Difference, APFloat::getZero(CI->getType()->getFltSemantics()));
-  return ConstantFP::get(CI->getType(), MaxVal);
+  // Constant folding will be handled by ConstantFoldLibCall2
+  return nullptr;
 }
 
 //===----------------------------------------------------------------------===//

@github-actions
Copy link

github-actions bot commented Dec 13, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Analysis/ConstantFolding.cpp llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp --diff_from_common_commit

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index dd4a3abf8..10e22b55c 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -3248,7 +3248,7 @@ static Constant *ConstantFoldLibCall2(StringRef Name, Type *Ty,
     Difference.subtract(Op2V, RoundingMode::NearestTiesToEven);
 
     APFloat MaxVal =
-      maximum(Difference, APFloat::getZero(Ty->getFltSemantics()));
+        maximum(Difference, APFloat::getZero(Ty->getFltSemantics()));
     return ConstantFP::get(Ty->getContext(), MaxVal);
     break;
   }

@github-actions
Copy link

github-actions bot commented Dec 13, 2025

🐧 Linux x64 Test Results

  • 167140 tests passed
  • 2950 tests skipped
  • 2 tests failed

Failed Tests

(click on a test name to see its output)

LLVM

LLVM.Transforms/InstCombine/fdim.ll
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/opt < /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll -passes=instcombine -S | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/opt -passes=instcombine -S
# note: command had no output on stdout or stderr
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll
# .---command stderr------------
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll:6:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 2.500000e+00
# |               ^
# | <stdin>:4:31: note: scanning from here
# | define double @fdim_double() {
# |                               ^
# | <stdin>:5:44: note: possible intended match here
# |  %dim = call double @fdim(double 1.050000e+01, double 8.000000e+00)
# |                                            ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll:14:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0.000000e+00
# |               ^
# | <stdin>:9:32: note: scanning from here
# | define double @fdim_double1() {
# |                                ^
# | <stdin>:10:44: note: possible intended match here
# |  %dim = call double @fdim(double 7.000000e+00, double 8.000000e+00)
# |                                            ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll:22:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret float 0.000000e+00
# |               ^
# | <stdin>:14:29: note: scanning from here
# | define float @fdim_float() {
# |                             ^
# | <stdin>:15:43: note: possible intended match here
# |  %dim = call float @fdimf(float 1.500000e+00, float 8.000000e+00)
# |                                           ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll:30:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret float 2.000000e+00
# |               ^
# | <stdin>:19:30: note: scanning from here
# | define float @fdim_float1() {
# |                              ^
# | <stdin>:20:43: note: possible intended match here
# |  %dim = call float @fdimf(float 1.000000e+01, float 8.000000e+00)
# |                                           ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll:72:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0x7FF0000000000000
# |               ^
# | <stdin>:41:33: note: scanning from here
# | define double @fdim_inf_ninf() {
# |                                 ^
# | <stdin>:42:23: note: possible intended match here
# |  %dim = call double @fdim(double 0x7FF0000000000000, double -0.000000e+00)
# |                       ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll:80:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0x7FF8000000000000
# |               ^
# | <stdin>:46:28: note: scanning from here
# | define double @fdim_inf() {
# |                            ^
# | <stdin>:47:50: note: possible intended match here
# |  %dim = call double @fdim(double 0x7FF0000000000000, double 0x7FF0000000000000)
# |                                                  ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll:88:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0.000000e+00
# |               ^
# | <stdin>:51:30: note: scanning from here
# | define double @fdim_nzero() {
# |                              ^
# | <stdin>:52:45: note: possible intended match here
# |  %dim = call double @fdim(double -0.000000e+00, double 0.000000e+00)
# |                                             ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll:105:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0x7FF8000000000000
# |               ^
# | <stdin>:61:29: note: scanning from here
# | define double @fdim_nan1() {
# |                             ^
# | <stdin>:62:44: note: possible intended match here
# |  %dim = call double @fdim(double 1.000000e+01, double 0x7FF8000000000000)
# |                                            ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll:114:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0x7FF8000000000000
# |               ^
# | <stdin>:66:29: note: scanning from here
# | define double @fdim_nan2() {
# |                             ^
# | <stdin>:67:23: note: possible intended match here
# |  %dim = call double @fdim(double 0x7FF8000000000000, double 1.400000e+00)
# |                       ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll:122:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0x7FFC000000000000
# |               ^
# | <stdin>:71:30: note: scanning from here
# | define double @fdim_snan1() {
# |                              ^
# | <stdin>:72:23: note: possible intended match here
# |  %dim = call double @fdim(double 0x7FF4000000000000, double 1.400000e+00)
# |                       ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll:130:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0x7FFC000000000000
# |               ^
# | <stdin>:76:30: note: scanning from here
# | define double @fdim_snan2() {
# |                              ^
# | <stdin>:77:44: note: possible intended match here
# |  %dim = call double @fdim(double 1.700000e+00, double 0x7FF4000000000000)
# |                                            ^
# | 
# | Input file: <stdin>
# | Check file: /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/fdim.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |             1: ; ModuleID = '<stdin>' 
# |             2: source_filename = "<stdin>" 
# |             3:  
# |             4: define double @fdim_double() { 
# | next:6'0                                     X error: no match found
# |             5:  %dim = call double @fdim(double 1.050000e+01, double 8.000000e+00) 
# | next:6'0       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:6'1                                                  ?                         possible intended match
# |             6:  ret double %dim 
# | next:6'0       ~~~~~~~~~~~~~~~~~
# |             7: } 
# | next:6'0       ~~
# |             8:  
# | next:6'0       ~
# |             9: define double @fdim_double1() { 
# | next:6'0       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:14'0                                     X error: no match found
# |            10:  %dim = call double @fdim(double 7.000000e+00, double 8.000000e+00) 
# | next:14'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:14'1                                                 ?                         possible intended match
# |            11:  ret double %dim 
# | next:14'0      ~~~~~~~~~~~~~~~~~
# |            12: } 
# | next:14'0      ~~
# |            13:  
# | next:14'0      ~
# |            14: define float @fdim_float() { 
# | next:14'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:22'0                                  X error: no match found
# |            15:  %dim = call float @fdimf(float 1.500000e+00, float 8.000000e+00) 
# | next:22'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:22'1                                                ?                        possible intended match
# |            16:  ret float %dim 
# | next:22'0      ~~~~~~~~~~~~~~~~
# |            17: } 
# | next:22'0      ~~
# |            18:  
# | next:22'0      ~
# |            19: define float @fdim_float1() { 
# | next:22'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:30'0                                   X error: no match found
# |            20:  %dim = call float @fdimf(float 1.000000e+01, float 8.000000e+00) 
# | next:30'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:30'1                                                ?                        possible intended match
# |            21:  ret float %dim 
# | next:30'0      ~~~~~~~~~~~~~~~~
# |            22: } 
# | next:30'0      ~~
# |            23:  
# | next:30'0      ~
# |            24: define double @fdim_poison1() { 
# | next:30'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |            25:  ret double poison 
# |             .
# |             .
# |             .
# |            36: define double @fdim_undef1() { 
# |            37:  %dim = call double @fdim(double undef, double 1.000000e+00) 
# |            38:  ret double %dim 
# |            39: } 
# |            40:  
# |            41: define double @fdim_inf_ninf() { 
# | next:72'0                                      X error: no match found
# |            42:  %dim = call double @fdim(double 0x7FF0000000000000, double -0.000000e+00) 
# | next:72'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:72'1                            ?                                                     possible intended match
# |            43:  ret double %dim 
# | next:72'0      ~~~~~~~~~~~~~~~~~
# |            44: } 
# | next:72'0      ~~
# |            45:  
# | next:72'0      ~
# |            46: define double @fdim_inf() { 
# | next:72'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:80'0                                 X error: no match found
# |            47:  %dim = call double @fdim(double 0x7FF0000000000000, double 0x7FF0000000000000) 
# | next:80'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:80'1                                                       ?                               possible intended match
# |            48:  ret double %dim 
# | next:80'0      ~~~~~~~~~~~~~~~~~
# |            49: } 
# | next:80'0      ~~
# |            50:  
# | next:80'0      ~
# |            51: define double @fdim_nzero() { 
# | next:80'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:88'0                                   X error: no match found
# |            52:  %dim = call double @fdim(double -0.000000e+00, double 0.000000e+00) 
# | next:88'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:88'1                                                  ?                         possible intended match
# |            53:  ret double %dim 
# | next:88'0      ~~~~~~~~~~~~~~~~~
# |            54: } 
# | next:88'0      ~~
# |            55:  
# | next:88'0      ~
# |            56: define double @fdim_strictfp() { 
# | next:88'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |            57:  %dim = call double @fdim(double 1.000000e+01, double 8.000000e+00) #1 
# |            58:  ret double %dim 
# |            59: } 
# |            60:  
# |            61: define double @fdim_nan1() { 
# | next:105'0                                 X error: no match found
# |            62:  %dim = call double @fdim(double 1.000000e+01, double 0x7FF8000000000000) 
# | next:105'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:105'1                                                ?                               possible intended match
# |            63:  ret double %dim 
# | next:105'0     ~~~~~~~~~~~~~~~~~
# |            64: } 
# | next:105'0     ~~
# |            65:  
# | next:105'0     ~
# |            66: define double @fdim_nan2() { 
# | next:105'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:114'0                                 X error: no match found
# |            67:  %dim = call double @fdim(double 0x7FF8000000000000, double 1.400000e+00) 
# | next:114'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:114'1                           ?                                                    possible intended match
# |            68:  ret double %dim 
# | next:114'0     ~~~~~~~~~~~~~~~~~
# |            69: } 
# | next:114'0     ~~
# |            70:  
# | next:114'0     ~
# |            71: define double @fdim_snan1() { 
# | next:114'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:122'0                                  X error: no match found
# |            72:  %dim = call double @fdim(double 0x7FF4000000000000, double 1.400000e+00) 
# | next:122'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:122'1                           ?                                                    possible intended match
# |            73:  ret double %dim 
# | next:122'0     ~~~~~~~~~~~~~~~~~
# |            74: } 
# | next:122'0     ~~
# |            75:  
# | next:122'0     ~
# |            76: define double @fdim_snan2() { 
# | next:122'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:130'0                                  X error: no match found
# |            77:  %dim = call double @fdim(double 1.700000e+00, double 0x7FF4000000000000) 
# | next:130'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:130'1                                                ?                               possible intended match
# |            78:  ret double %dim 
# | next:130'0     ~~~~~~~~~~~~~~~~~
# |            79: } 
# | next:130'0     ~~
# |            80:  
# | next:130'0     ~
# |            81: ; Function Attrs: memory(none) 
# | next:130'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |            82: declare double @fdim(double, double) #0 
# | next:130'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |             .
# |             .
# |             .
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

LLVM.Transforms/InstCombine/win-fdim.ll
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/opt /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/win-fdim.ll -passes=instcombine -S -mtriple=i386-pc-windows-msvc | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/win-fdim.ll --check-prefixes=MSVC19
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/opt /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/win-fdim.ll -passes=instcombine -S -mtriple=i386-pc-windows-msvc
# note: command had no output on stdout or stderr
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/win-fdim.ll --check-prefixes=MSVC19
# .---command stderr------------
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/win-fdim.ll:6:16: error: MSVC19-NEXT: expected string not found in input
# | ; MSVC19-NEXT: ret double 2.500000e+00
# |                ^
# | <stdin>:6:31: note: scanning from here
# | define double @fdim_double() {
# |                               ^
# | <stdin>:7:44: note: possible intended match here
# |  %dim = call double @fdim(double 1.050000e+01, double 8.000000e+00)
# |                                            ^
# | 
# | Input file: <stdin>
# | Check file: /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/win-fdim.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |           1: ; ModuleID = '/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/win-fdim.ll' 
# |           2: source_filename = "/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/Transforms/InstCombine/win-fdim.ll" 
# |           3: target datalayout = "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32-a:0:32-S32" 
# |           4: target triple = "i386-pc-windows-msvc" 
# |           5:  
# |           6: define double @fdim_double() { 
# | next:6'0                                   X error: no match found
# |           7:  %dim = call double @fdim(double 1.050000e+01, double 8.000000e+00) 
# | next:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:6'1                                                ?                         possible intended match
# |           8:  ret double %dim 
# | next:6'0     ~~~~~~~~~~~~~~~~~
# |           9: } 
# | next:6'0     ~~
# |          10:  
# | next:6'0     ~
# |          11: define float @fdim_float() { 
# | next:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |          12:  %dim = call float @fdimf(float 1.500000e+00, float 8.000000e+00) 
# |           .
# |           .
# |           .
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

@github-actions
Copy link

github-actions bot commented Dec 13, 2025

🪟 Windows x64 Test Results

  • 128630 tests passed
  • 2817 tests skipped
  • 2 tests failed

Failed Tests

(click on a test name to see its output)

LLVM

LLVM.Transforms/InstCombine/fdim.ll
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
c:\_work\llvm-project\llvm-project\build\bin\opt.exe < C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll -passes=instcombine -S | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\opt.exe' -passes=instcombine -S
# note: command had no output on stdout or stderr
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' 'C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll'
# .---command stderr------------
# | C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll:6:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 2.500000e+00
# |               ^
# | <stdin>:4:31: note: scanning from here
# | define double @fdim_double() {
# |                               ^
# | <stdin>:5:44: note: possible intended match here
# |  %dim = call double @fdim(double 1.050000e+01, double 8.000000e+00)
# |                                            ^
# | C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll:14:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0.000000e+00
# |               ^
# | <stdin>:9:32: note: scanning from here
# | define double @fdim_double1() {
# |                                ^
# | <stdin>:10:44: note: possible intended match here
# |  %dim = call double @fdim(double 7.000000e+00, double 8.000000e+00)
# |                                            ^
# | C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll:22:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret float 0.000000e+00
# |               ^
# | <stdin>:14:29: note: scanning from here
# | define float @fdim_float() {
# |                             ^
# | <stdin>:15:43: note: possible intended match here
# |  %dim = call float @fdimf(float 1.500000e+00, float 8.000000e+00)
# |                                           ^
# | C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll:30:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret float 2.000000e+00
# |               ^
# | <stdin>:19:30: note: scanning from here
# | define float @fdim_float1() {
# |                              ^
# | <stdin>:20:43: note: possible intended match here
# |  %dim = call float @fdimf(float 1.000000e+01, float 8.000000e+00)
# |                                           ^
# | C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll:72:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0x7FF0000000000000
# |               ^
# | <stdin>:41:33: note: scanning from here
# | define double @fdim_inf_ninf() {
# |                                 ^
# | <stdin>:42:23: note: possible intended match here
# |  %dim = call double @fdim(double 0x7FF0000000000000, double -0.000000e+00)
# |                       ^
# | C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll:80:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0x7FF8000000000000
# |               ^
# | <stdin>:46:28: note: scanning from here
# | define double @fdim_inf() {
# |                            ^
# | <stdin>:47:50: note: possible intended match here
# |  %dim = call double @fdim(double 0x7FF0000000000000, double 0x7FF0000000000000)
# |                                                  ^
# | C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll:88:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0.000000e+00
# |               ^
# | <stdin>:51:30: note: scanning from here
# | define double @fdim_nzero() {
# |                              ^
# | <stdin>:52:45: note: possible intended match here
# |  %dim = call double @fdim(double -0.000000e+00, double 0.000000e+00)
# |                                             ^
# | C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll:105:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0x7FF8000000000000
# |               ^
# | <stdin>:61:29: note: scanning from here
# | define double @fdim_nan1() {
# |                             ^
# | <stdin>:62:44: note: possible intended match here
# |  %dim = call double @fdim(double 1.000000e+01, double 0x7FF8000000000000)
# |                                            ^
# | C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll:114:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0x7FF8000000000000
# |               ^
# | <stdin>:66:29: note: scanning from here
# | define double @fdim_nan2() {
# |                             ^
# | <stdin>:67:23: note: possible intended match here
# |  %dim = call double @fdim(double 0x7FF8000000000000, double 1.400000e+00)
# |                       ^
# | C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll:122:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0x7FFC000000000000
# |               ^
# | <stdin>:71:30: note: scanning from here
# | define double @fdim_snan1() {
# |                              ^
# | <stdin>:72:23: note: possible intended match here
# |  %dim = call double @fdim(double 0x7FF4000000000000, double 1.400000e+00)
# |                       ^
# | C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll:130:15: error: CHECK-NEXT: expected string not found in input
# | ; CHECK-NEXT: ret double 0x7FFC000000000000
# |               ^
# | <stdin>:76:30: note: scanning from here
# | define double @fdim_snan2() {
# |                              ^
# | <stdin>:77:44: note: possible intended match here
# |  %dim = call double @fdim(double 1.700000e+00, double 0x7FF4000000000000)
# |                                            ^
# | 
# | Input file: <stdin>
# | Check file: C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\fdim.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |             1: ; ModuleID = '<stdin>' 
# |             2: source_filename = "<stdin>" 
# |             3:  
# |             4: define double @fdim_double() { 
# | next:6'0                                     X error: no match found
# |             5:  %dim = call double @fdim(double 1.050000e+01, double 8.000000e+00) 
# | next:6'0       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:6'1                                                  ?                         possible intended match
# |             6:  ret double %dim 
# | next:6'0       ~~~~~~~~~~~~~~~~~
# |             7: } 
# | next:6'0       ~~
# |             8:  
# | next:6'0       ~
# |             9: define double @fdim_double1() { 
# | next:6'0       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:14'0                                     X error: no match found
# |            10:  %dim = call double @fdim(double 7.000000e+00, double 8.000000e+00) 
# | next:14'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:14'1                                                 ?                         possible intended match
# |            11:  ret double %dim 
# | next:14'0      ~~~~~~~~~~~~~~~~~
# |            12: } 
# | next:14'0      ~~
# |            13:  
# | next:14'0      ~
# |            14: define float @fdim_float() { 
# | next:14'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:22'0                                  X error: no match found
# |            15:  %dim = call float @fdimf(float 1.500000e+00, float 8.000000e+00) 
# | next:22'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:22'1                                                ?                        possible intended match
# |            16:  ret float %dim 
# | next:22'0      ~~~~~~~~~~~~~~~~
# |            17: } 
# | next:22'0      ~~
# |            18:  
# | next:22'0      ~
# |            19: define float @fdim_float1() { 
# | next:22'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:30'0                                   X error: no match found
# |            20:  %dim = call float @fdimf(float 1.000000e+01, float 8.000000e+00) 
# | next:30'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:30'1                                                ?                        possible intended match
# |            21:  ret float %dim 
# | next:30'0      ~~~~~~~~~~~~~~~~
# |            22: } 
# | next:30'0      ~~
# |            23:  
# | next:30'0      ~
# |            24: define double @fdim_poison1() { 
# | next:30'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |            25:  ret double poison 
# |             .
# |             .
# |             .
# |            36: define double @fdim_undef1() { 
# |            37:  %dim = call double @fdim(double undef, double 1.000000e+00) 
# |            38:  ret double %dim 
# |            39: } 
# |            40:  
# |            41: define double @fdim_inf_ninf() { 
# | next:72'0                                      X error: no match found
# |            42:  %dim = call double @fdim(double 0x7FF0000000000000, double -0.000000e+00) 
# | next:72'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:72'1                            ?                                                     possible intended match
# |            43:  ret double %dim 
# | next:72'0      ~~~~~~~~~~~~~~~~~
# |            44: } 
# | next:72'0      ~~
# |            45:  
# | next:72'0      ~
# |            46: define double @fdim_inf() { 
# | next:72'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:80'0                                 X error: no match found
# |            47:  %dim = call double @fdim(double 0x7FF0000000000000, double 0x7FF0000000000000) 
# | next:80'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:80'1                                                       ?                               possible intended match
# |            48:  ret double %dim 
# | next:80'0      ~~~~~~~~~~~~~~~~~
# |            49: } 
# | next:80'0      ~~
# |            50:  
# | next:80'0      ~
# |            51: define double @fdim_nzero() { 
# | next:80'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:88'0                                   X error: no match found
# |            52:  %dim = call double @fdim(double -0.000000e+00, double 0.000000e+00) 
# | next:88'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:88'1                                                  ?                         possible intended match
# |            53:  ret double %dim 
# | next:88'0      ~~~~~~~~~~~~~~~~~
# |            54: } 
# | next:88'0      ~~
# |            55:  
# | next:88'0      ~
# |            56: define double @fdim_strictfp() { 
# | next:88'0      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |            57:  %dim = call double @fdim(double 1.000000e+01, double 8.000000e+00) #1 
# |            58:  ret double %dim 
# |            59: } 
# |            60:  
# |            61: define double @fdim_nan1() { 
# | next:105'0                                 X error: no match found
# |            62:  %dim = call double @fdim(double 1.000000e+01, double 0x7FF8000000000000) 
# | next:105'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:105'1                                                ?                               possible intended match
# |            63:  ret double %dim 
# | next:105'0     ~~~~~~~~~~~~~~~~~
# |            64: } 
# | next:105'0     ~~
# |            65:  
# | next:105'0     ~
# |            66: define double @fdim_nan2() { 
# | next:105'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:114'0                                 X error: no match found
# |            67:  %dim = call double @fdim(double 0x7FF8000000000000, double 1.400000e+00) 
# | next:114'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:114'1                           ?                                                    possible intended match
# |            68:  ret double %dim 
# | next:114'0     ~~~~~~~~~~~~~~~~~
# |            69: } 
# | next:114'0     ~~
# |            70:  
# | next:114'0     ~
# |            71: define double @fdim_snan1() { 
# | next:114'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:122'0                                  X error: no match found
# |            72:  %dim = call double @fdim(double 0x7FF4000000000000, double 1.400000e+00) 
# | next:122'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:122'1                           ?                                                    possible intended match
# |            73:  ret double %dim 
# | next:122'0     ~~~~~~~~~~~~~~~~~
# |            74: } 
# | next:122'0     ~~
# |            75:  
# | next:122'0     ~
# |            76: define double @fdim_snan2() { 
# | next:122'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:130'0                                  X error: no match found
# |            77:  %dim = call double @fdim(double 1.700000e+00, double 0x7FF4000000000000) 
# | next:130'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:130'1                                                ?                               possible intended match
# |            78:  ret double %dim 
# | next:130'0     ~~~~~~~~~~~~~~~~~
# |            79: } 
# | next:130'0     ~~
# |            80:  
# | next:130'0     ~
# |            81: ; Function Attrs: memory(none) 
# | next:130'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |            82: declare double @fdim(double, double) #0 
# | next:130'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |             .
# |             .
# |             .
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

LLVM.Transforms/InstCombine/win-fdim.ll
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
c:\_work\llvm-project\llvm-project\build\bin\opt.exe C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\win-fdim.ll -passes=instcombine -S -mtriple=i386-pc-windows-msvc | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\win-fdim.ll --check-prefixes=MSVC19
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\opt.exe' 'C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\win-fdim.ll' -passes=instcombine -S -mtriple=i386-pc-windows-msvc
# note: command had no output on stdout or stderr
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' 'C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\win-fdim.ll' --check-prefixes=MSVC19
# .---command stderr------------
# | C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\win-fdim.ll:6:16: error: MSVC19-NEXT: expected string not found in input
# | ; MSVC19-NEXT: ret double 2.500000e+00
# |                ^
# | <stdin>:6:31: note: scanning from here
# | define double @fdim_double() {
# |                               ^
# | <stdin>:7:44: note: possible intended match here
# |  %dim = call double @fdim(double 1.050000e+01, double 8.000000e+00)
# |                                            ^
# | 
# | Input file: <stdin>
# | Check file: C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\win-fdim.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |           1: ; ModuleID = 'C:\_work\llvm-project\llvm-project\llvm\test\Transforms\InstCombine\win-fdim.ll' 
# |           2: source_filename = "C:\\_work\\llvm-project\\llvm-project\\llvm\\test\\Transforms\\InstCombine\\win-fdim.ll" 
# |           3: target datalayout = "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32-a:0:32-S32" 
# |           4: target triple = "i386-pc-windows-msvc" 
# |           5:  
# |           6: define double @fdim_double() { 
# | next:6'0                                   X error: no match found
# |           7:  %dim = call double @fdim(double 1.050000e+01, double 8.000000e+00) 
# | next:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | next:6'1                                                ?                         possible intended match
# |           8:  ret double %dim 
# | next:6'0     ~~~~~~~~~~~~~~~~~
# |           9: } 
# | next:6'0     ~~
# |          10:  
# | next:6'0     ~
# |          11: define float @fdim_float() { 
# | next:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |          12:  %dim = call float @fdimf(float 1.500000e+00, float 8.000000e+00) 
# |           .
# |           .
# |           .
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

Copy link
Contributor

@antoniofrighetto antoniofrighetto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should introduce fdim names here too, to allow constant folding:

case 'f':
return Name == "fabs" || Name == "fabsf" ||
Name == "floor" || Name == "floorf" ||
Name == "fmod" || Name == "fmodf";

(I wonder if they should be intrinsics though)

@antoniofrighetto antoniofrighetto changed the title Resolving #171877 [SimplifyLibCalls] Move constant folding logic in ConstantFoldLibCall2 Dec 15, 2025
if (isa<PoisonValue>(CI->getArgOperand(0)))
return CI->getArgOperand(0);
if (isa<PoisonValue>(CI->getArgOperand(1)))
return CI->getArgOperand(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The poison cases shouldn't be in this file either.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikic Sorry, I'm new to llvm contribution, do you mean poison cases should just be removed entirely? Because as I understand it, ConstantFoldLibCall2 only takes in operands of known constants

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Poison values are also constants. Though I don't think it matters since we always set noundef for operands passed to fdim: https://godbolt.org/z/9MhdToo6W

@dtcxzyw
Copy link
Member

dtcxzyw commented Dec 15, 2025

(I wonder if they should be intrinsics though)

Currently we cannot benefit from the vectorization of fdim (and other transformations except for constant folding). So it may be too early to turn it into intrinsics.

@dtcxzyw dtcxzyw requested a review from arsenm December 15, 2025 14:18
Copy link
Contributor

@antoniofrighetto antoniofrighetto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Point above still unresolved?

Ronxvier and others added 2 commits December 16, 2025 01:32
remove break that isn't reached

Co-authored-by: Antonio Frighetto <me@antoniofrighetto.com>
Comment on lines +3247 to +3251
APFloat Difference = Op1V;
Difference.subtract(Op2V, RoundingMode::NearestTiesToEven);

APFloat MaxVal =
maximum(Difference, APFloat::getZero(Ty->getFltSemantics()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual implementation logic should probably be in APFloat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ConstantFolding] Move LibCallSimplifier::optimizeFdim into ConstantFolding

6 participants