[llvm] [InstCombine] Revert FSub optimization from #157757 (PR #158315)
Vedant Paranjape via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 12 08:46:26 PDT 2025
https://github.com/VedantParanjape created https://github.com/llvm/llvm-project/pull/158315
Since FSub X, 0 gets canoncialised to FAdd X, -0 the said optimization didn't make much sense for FSub. Remove it from IC and the adjoined testcase.
>From 2facfade05df76646128a20f3f4a9f4fd2fcd7ab Mon Sep 17 00:00:00 2001
From: Vedant Paranjape <vedantparanjape160201 at gmail.com>
Date: Fri, 12 Sep 2025 11:43:49 -0400
Subject: [PATCH] [InstCombine] Revert FSub optimization from #157757
Since FSub X, 0 gets canoncialised to FAdd X, -0 the said optimization
didn't make much sense for FSub. Remove it from IC and the adjoined
testcase.
---
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 10 ----------
.../InstCombine/fold-fadd-with-zero-gh154238.ll | 11 -----------
2 files changed, 21 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 726d09aa26941..00951fde0cf8a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -3155,16 +3155,6 @@ Instruction *InstCombinerImpl::visitFSub(BinaryOperator &I) {
Value *X, *Y;
Constant *C;
- // B = fsub A, 0.0
- // Z = Op B
- // can be transformed into
- // Z = Op A
- // Where Op is such that we can ignore sign of 0 in fsub
- Value *A;
- if (match(&I, m_OneUse(m_FSub(m_Value(A), m_AnyZeroFP()))) &&
- canIgnoreSignBitOfZero(*I.use_begin()))
- return replaceInstUsesWith(I, A);
-
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
// If Op0 is not -0.0 or we can ignore -0.0: Z - (X - Y) --> Z + (Y - X)
// Canonicalize to fadd to make analysis easier.
diff --git a/llvm/test/Transforms/InstCombine/fold-fadd-with-zero-gh154238.ll b/llvm/test/Transforms/InstCombine/fold-fadd-with-zero-gh154238.ll
index b9d951dc2945a..f9f0ca8a08bcb 100644
--- a/llvm/test/Transforms/InstCombine/fold-fadd-with-zero-gh154238.ll
+++ b/llvm/test/Transforms/InstCombine/fold-fadd-with-zero-gh154238.ll
@@ -24,14 +24,3 @@ define float @src2(float %arg1) {
%v4 = fsub float %v2, %v3
ret float %v4
}
-
-define float @src_sub(float %arg1) {
-; CHECK-LABEL: define float @src_sub(
-; CHECK-SAME: float [[ARG1:%.*]]) {
-; CHECK-NEXT: [[V3:%.*]] = call float @llvm.fabs.f32(float [[ARG1]])
-; CHECK-NEXT: ret float [[V3]]
-;
- %v2 = fsub float %arg1, 0.000000e+00
- %v3 = call float @llvm.fabs.f32(float %v2)
- ret float %v3
-}
More information about the llvm-commits
mailing list