[llvm] [InstCombine] Implement `fcmp (fadd x, 0.0), y` => `fcmp x, y` optimization (PR #88476)
Vlad Mishel via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 15 12:38:14 PDT 2024
https://github.com/vmishelcs updated https://github.com/llvm/llvm-project/pull/88476
>From 0812766556cd9f528c36a83f2be924ea208046ed Mon Sep 17 00:00:00 2001
From: Vladimir Mishel <vmishel at outlook.com>
Date: Thu, 11 Apr 2024 23:00:08 -0700
Subject: [PATCH 1/5] [InstCombine] Add tests for fcmp combine
---
llvm/test/Transforms/InstCombine/fcmp.ll | 156 +++++++++++++++++++++++
1 file changed, 156 insertions(+)
diff --git a/llvm/test/Transforms/InstCombine/fcmp.ll b/llvm/test/Transforms/InstCombine/fcmp.ll
index f2701d16d0f3d1..c9bb1fc5fcd2f6 100644
--- a/llvm/test/Transforms/InstCombine/fcmp.ll
+++ b/llvm/test/Transforms/InstCombine/fcmp.ll
@@ -1284,3 +1284,159 @@ define <1 x i1> @bitcast_1vec_eq0(i32 %x) {
%cmp = fcmp oeq <1 x float> %f, zeroinitializer
ret <1 x i1> %cmp
}
+
+; Simplify fcmp (x + 0.0), y => fcmp x, y
+
+define i1 @fcmp_fadd_zero_ugt(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_ugt(
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ugt float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp ugt float %add, %y
+ ret i1 %cmp
+}
+
+define i1 @fcmp_fadd_zero_uge(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_uge(
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[CMP:%.*]] = fcmp uge float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp uge float %add, %y
+ ret i1 %cmp
+}
+
+define i1 @fcmp_fadd_zero_ogt(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_ogt(
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp ogt float %add, %y
+ ret i1 %cmp
+}
+
+define i1 @fcmp_fadd_zero_oge(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_oge(
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[CMP:%.*]] = fcmp oge float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp oge float %add, %y
+ ret i1 %cmp
+}
+
+define i1 @fcmp_fadd_zero_ult(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_ult(
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ult float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp ult float %add, %y
+ ret i1 %cmp
+}
+
+define i1 @fcmp_fadd_zero_ule(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_ule(
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ule float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp ule float %add, %y
+ ret i1 %cmp
+}
+
+define i1 @fcmp_fadd_zero_olt(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_olt(
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[CMP:%.*]] = fcmp olt float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp olt float %add, %y
+ ret i1 %cmp
+}
+
+define i1 @fcmp_fadd_zero_ole(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_ole(
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ole float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp ole float %add, %y
+ ret i1 %cmp
+}
+
+define i1 @fcmp_fadd_zero_oeq(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_oeq(
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp oeq float %add, %y
+ ret i1 %cmp
+}
+
+define i1 @fcmp_fadd_zero_one(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_one(
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[CMP:%.*]] = fcmp one float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp one float %add, %y
+ ret i1 %cmp
+}
+
+define i1 @fcmp_fadd_zero_ueq(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_ueq(
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ueq float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp ueq float %add, %y
+ ret i1 %cmp
+}
+
+define i1 @fcmp_fadd_zero_une(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_une(
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp une float %add, %y
+ ret i1 %cmp
+}
+
+define i1 @fcmp_fadd_zero_ord(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_ord(
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ord float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp ord float %add, %y
+ ret i1 %cmp
+}
+
+define i1 @fcmp_fadd_zero_uno(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_uno(
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[CMP:%.*]] = fcmp uno float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp uno float %add, %y
+ ret i1 %cmp
+}
>From f7092dd847df7749443650e388bb32dc7bd37a66 Mon Sep 17 00:00:00 2001
From: Vladimir Mishel <vmishel at outlook.com>
Date: Thu, 11 Apr 2024 23:26:49 -0700
Subject: [PATCH 2/5] [InstCombine] Implement `fcmp (fadd x, 0.0), y` -> `fcmp
x, y`
---
.../InstCombine/InstCombineCompares.cpp | 7 ++++
llvm/test/Transforms/InstCombine/fcmp.ll | 42 +++++++------------
2 files changed, 21 insertions(+), 28 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 7292bb62702aaa..67f3e0386402b1 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -8100,6 +8100,13 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
return new FCmpInst(I.getSwappedPredicate(), X, NegC, "", &I);
}
+ // fcmp (fadd X, 0.0), Y --> fcmp X, Y
+ if (match(Op0, m_FAdd(m_Value(X), m_APFloat(C))) && C->isZero()) {
+ if (match(Op1, m_Value(Y))) {
+ return new FCmpInst(Pred, X, Y, "", &I);
+ }
+ }
+
if (match(Op0, m_FPExt(m_Value(X)))) {
// fcmp (fpext X), (fpext Y) -> fcmp X, Y
if (match(Op1, m_FPExt(m_Value(Y))) && X->getType() == Y->getType())
diff --git a/llvm/test/Transforms/InstCombine/fcmp.ll b/llvm/test/Transforms/InstCombine/fcmp.ll
index c9bb1fc5fcd2f6..003483c217771c 100644
--- a/llvm/test/Transforms/InstCombine/fcmp.ll
+++ b/llvm/test/Transforms/InstCombine/fcmp.ll
@@ -1289,8 +1289,7 @@ define <1 x i1> @bitcast_1vec_eq0(i32 %x) {
define i1 @fcmp_fadd_zero_ugt(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_ugt(
-; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[CMP:%.*]] = fcmp ugt float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ugt float [[ADD:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = fadd float %x, 0.000000e+00
@@ -1300,8 +1299,7 @@ define i1 @fcmp_fadd_zero_ugt(float %x, float %y) {
define i1 @fcmp_fadd_zero_uge(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_uge(
-; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[CMP:%.*]] = fcmp uge float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = fcmp uge float [[ADD:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = fadd float %x, 0.000000e+00
@@ -1311,8 +1309,7 @@ define i1 @fcmp_fadd_zero_uge(float %x, float %y) {
define i1 @fcmp_fadd_zero_ogt(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_ogt(
-; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[ADD:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = fadd float %x, 0.000000e+00
@@ -1322,8 +1319,7 @@ define i1 @fcmp_fadd_zero_ogt(float %x, float %y) {
define i1 @fcmp_fadd_zero_oge(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_oge(
-; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[CMP:%.*]] = fcmp oge float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = fcmp oge float [[ADD:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = fadd float %x, 0.000000e+00
@@ -1333,8 +1329,7 @@ define i1 @fcmp_fadd_zero_oge(float %x, float %y) {
define i1 @fcmp_fadd_zero_ult(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_ult(
-; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[CMP:%.*]] = fcmp ult float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ult float [[ADD:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = fadd float %x, 0.000000e+00
@@ -1344,8 +1339,7 @@ define i1 @fcmp_fadd_zero_ult(float %x, float %y) {
define i1 @fcmp_fadd_zero_ule(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_ule(
-; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[CMP:%.*]] = fcmp ule float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ule float [[ADD:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = fadd float %x, 0.000000e+00
@@ -1355,8 +1349,7 @@ define i1 @fcmp_fadd_zero_ule(float %x, float %y) {
define i1 @fcmp_fadd_zero_olt(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_olt(
-; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[CMP:%.*]] = fcmp olt float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = fcmp olt float [[ADD:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = fadd float %x, 0.000000e+00
@@ -1366,8 +1359,7 @@ define i1 @fcmp_fadd_zero_olt(float %x, float %y) {
define i1 @fcmp_fadd_zero_ole(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_ole(
-; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[CMP:%.*]] = fcmp ole float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ole float [[ADD:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = fadd float %x, 0.000000e+00
@@ -1377,8 +1369,7 @@ define i1 @fcmp_fadd_zero_ole(float %x, float %y) {
define i1 @fcmp_fadd_zero_oeq(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_oeq(
-; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[ADD:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = fadd float %x, 0.000000e+00
@@ -1388,8 +1379,7 @@ define i1 @fcmp_fadd_zero_oeq(float %x, float %y) {
define i1 @fcmp_fadd_zero_one(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_one(
-; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[CMP:%.*]] = fcmp one float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = fcmp one float [[ADD:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = fadd float %x, 0.000000e+00
@@ -1399,8 +1389,7 @@ define i1 @fcmp_fadd_zero_one(float %x, float %y) {
define i1 @fcmp_fadd_zero_ueq(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_ueq(
-; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[CMP:%.*]] = fcmp ueq float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ueq float [[ADD:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = fadd float %x, 0.000000e+00
@@ -1410,8 +1399,7 @@ define i1 @fcmp_fadd_zero_ueq(float %x, float %y) {
define i1 @fcmp_fadd_zero_une(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_une(
-; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[ADD:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = fadd float %x, 0.000000e+00
@@ -1421,8 +1409,7 @@ define i1 @fcmp_fadd_zero_une(float %x, float %y) {
define i1 @fcmp_fadd_zero_ord(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_ord(
-; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[CMP:%.*]] = fcmp ord float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ord float [[ADD:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = fadd float %x, 0.000000e+00
@@ -1432,8 +1419,7 @@ define i1 @fcmp_fadd_zero_ord(float %x, float %y) {
define i1 @fcmp_fadd_zero_uno(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_uno(
-; CHECK-NEXT: [[ADD:%.*]] = fadd float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT: [[CMP:%.*]] = fcmp uno float [[ADD]], [[Y:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = fcmp uno float [[ADD:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%add = fadd float %x, 0.000000e+00
>From 9fa945d1c6f4aaa3e21f4b3aff36571aca79e439 Mon Sep 17 00:00:00 2001
From: Vladimir Mishel <vmishel at outlook.com>
Date: Fri, 12 Apr 2024 19:34:11 -0700
Subject: [PATCH 3/5] [InstCombine] Implement dtcxzyw's suggested changes
---
.../Transforms/InstCombine/InstCombineCompares.cpp | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 67f3e0386402b1..88e025387a94af 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -8101,11 +8101,12 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
}
// fcmp (fadd X, 0.0), Y --> fcmp X, Y
- if (match(Op0, m_FAdd(m_Value(X), m_APFloat(C))) && C->isZero()) {
- if (match(Op1, m_Value(Y))) {
- return new FCmpInst(Pred, X, Y, "", &I);
- }
- }
+ if (match(Op0, m_FAdd(m_Value(X), m_AnyZeroFP())))
+ return new FCmpInst(Pred, X, Op1, "", &I);
+
+ // fcmp X, (fadd Y, 0.0) --> fcmp X, Y
+ if (match(Op1, m_FAdd(m_Value(Y), m_AnyZeroFP())))
+ return new FCmpInst(Pred, Op0, Y, "", &I);
if (match(Op0, m_FPExt(m_Value(X)))) {
// fcmp (fpext X), (fpext Y) -> fcmp X, Y
>From daca19f7cab4b98313d7a59d2e4c361d2e9f298e Mon Sep 17 00:00:00 2001
From: Vladimir Mishel <vmishel at outlook.com>
Date: Fri, 12 Apr 2024 19:42:25 -0700
Subject: [PATCH 4/5] [InstCombine] Added tests for swap, vectors, and fast
flag
---
llvm/test/Transforms/InstCombine/fcmp.ll | 30 ++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/llvm/test/Transforms/InstCombine/fcmp.ll b/llvm/test/Transforms/InstCombine/fcmp.ll
index 003483c217771c..c5cba0a2903a6c 100644
--- a/llvm/test/Transforms/InstCombine/fcmp.ll
+++ b/llvm/test/Transforms/InstCombine/fcmp.ll
@@ -1426,3 +1426,33 @@ define i1 @fcmp_fadd_zero_uno(float %x, float %y) {
%cmp = fcmp uno float %add, %y
ret i1 %cmp
}
+
+define i1 @fcmp_fadd_zero_switched(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_switched(
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ult float [[Y:%.*]], [[X:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %y, 0.000000e+00
+ %cmp = fcmp ugt float %x, %add
+ ret i1 %cmp
+}
+
+define <2 x i1> @fcmp_fadd_zero_vec(<2 x float> %x, <2 x float> %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_vec(
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ugt <2 x float> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %add = fadd <2 x float> %x, <float 0.0, float -0.0>
+ %cmp = fcmp ugt <2 x float> %add, %y
+ ret <2 x i1> %cmp
+}
+
+define i1 @fcmp_fadd_zero_fast(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_zero_fast(
+; CHECK-NEXT: [[CMP:%.*]] = fcmp fast ugt float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd fast float %x, 0.000000e+00
+ %cmp = fcmp fast ugt float %add, %y
+ ret i1 %cmp
+}
>From a460fb08a0e5b57f02d44b0bbdf40952d5d42ac1 Mon Sep 17 00:00:00 2001
From: Vladimir Mishel <vmishel at outlook.com>
Date: Mon, 15 Apr 2024 12:38:02 -0700
Subject: [PATCH 5/5] [InstCombine] Added tests as instructed by `arsenm`
---
llvm/test/Transforms/InstCombine/fcmp.ll | 34 ++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/llvm/test/Transforms/InstCombine/fcmp.ll b/llvm/test/Transforms/InstCombine/fcmp.ll
index c5cba0a2903a6c..069512b0f2d8eb 100644
--- a/llvm/test/Transforms/InstCombine/fcmp.ll
+++ b/llvm/test/Transforms/InstCombine/fcmp.ll
@@ -1427,6 +1427,16 @@ define i1 @fcmp_fadd_zero_uno(float %x, float %y) {
ret i1 %cmp
}
+define i1 @fcmp_fadd_neg_zero(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_neg_zero(
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ugt float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, -0.000000e+00
+ %cmp = fcmp ugt float %add, %y
+ ret i1 %cmp
+}
+
define i1 @fcmp_fadd_zero_switched(float %x, float %y) {
; CHECK-LABEL: @fcmp_fadd_zero_switched(
; CHECK-NEXT: [[CMP:%.*]] = fcmp ult float [[Y:%.*]], [[X:%.*]]
@@ -1447,8 +1457,8 @@ define <2 x i1> @fcmp_fadd_zero_vec(<2 x float> %x, <2 x float> %y) {
ret <2 x i1> %cmp
}
-define i1 @fcmp_fadd_zero_fast(float %x, float %y) {
-; CHECK-LABEL: @fcmp_fadd_zero_fast(
+define i1 @fcmp_fast_fadd_fast_zero(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fast_fadd_fast_zero(
; CHECK-NEXT: [[CMP:%.*]] = fcmp fast ugt float [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
@@ -1456,3 +1466,23 @@ define i1 @fcmp_fadd_zero_fast(float %x, float %y) {
%cmp = fcmp fast ugt float %add, %y
ret i1 %cmp
}
+
+define i1 @fcmp_fast_fadd_zero(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fast_fadd_zero(
+; CHECK-NEXT: [[CMP:%.*]] = fcmp fast ugt float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd float %x, 0.000000e+00
+ %cmp = fcmp fast ugt float %add, %y
+ ret i1 %cmp
+}
+
+define i1 @fcmp_fadd_fast_zero(float %x, float %y) {
+; CHECK-LABEL: @fcmp_fadd_fast_zero(
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ugt float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %add = fadd fast float %x, 0.000000e+00
+ %cmp = fcmp ugt float %add, %y
+ ret i1 %cmp
+}
More information about the llvm-commits
mailing list