[llvm] [InstCombine] Transform (fcmp + fadd + sel) into (fcmp + sel + fadd) (PR #106492)
Rajat Bajpai via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 30 09:25:47 PDT 2024
================
@@ -0,0 +1,634 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+; fcmp OGT + fadd + sel => fcmp OGT + sel => fmaxnum
+
+define float @test_fcmp_ogt_fadd_select_constant(float %in) {
----------------
rajatbajpai wrote:
This change does the below transformation, which seems to be safe https://alive2.llvm.org/ce/z/3XQb24.
```
define float @src_test_fcmp_ogt_fadd_select_constant(float %in) {
%cmp1 = fcmp ogt float %in, 0.000000e+00
%add = fadd float %in, 1.000000e+00
%sel = select nnan nsz i1 %cmp1, float %add, float 1.000000e+00
ret float %sel
}
```
**=>**
```
define float @tgt_test_fcmp_ogt_fadd_select_constant(float %in) {
%cmp1 = fcmp ogt float %in, 0.000000e+00
%sel = select nnan nsz i1 %cmp1, float %in, float 0.000000e+00
%add = fadd float %sel, 1.000000e+00
ret float %add
}
```
The transformation from `tgt_test_fcmp_ogt_fadd_select_constant` to `llvm.maxnum.f32` is an existing one, as shown here https://godbolt.org/z/6n4Tfrx9e. If this transformation is incorrect, we should probably address it in a separate PR.
https://github.com/llvm/llvm-project/pull/106492
More information about the llvm-commits
mailing list