Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5710,7 +5710,9 @@ simplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF,
// fadd X, 0 ==> X, when we know X is not -0
if (canIgnoreSNaN(ExBehavior, FMF))
if (match(Op1, m_PosZeroFP()) &&
(FMF.noSignedZeros() || cannotBeNegativeZero(Op0, Q)))
(FMF.noSignedZeros() || cannotBeNegativeZero(Op0, Q) ||
(Q.CxtI && !Q.CxtI->use_empty() &&
canIgnoreSignBitOfZero(*(Q.CxtI->use_begin())))))
Copy link
Contributor

Choose a reason for hiding this comment

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

You can't do use-based reasoning inside InstSimplify, this must happen in InstCombine.

return Op0;

if (!isDefaultFPEnvironment(ExBehavior, Rounding))
Expand Down
5 changes: 2 additions & 3 deletions llvm/test/CodeGen/AMDGPU/fcanonicalize-elimination.ll
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,8 @@ define amdgpu_kernel void @test_no_fold_canonicalize_fcopysign_value_f32(ptr add
}

; GCN-LABEL: test_fold_canonicalize_fabs_value_f32:
; GCN: v_and_b32_e32 [[V:v[0-9]+]], 0x7fffffff, v{{[0-9]+}}
; GCN-NOT: v_mul
; GCN-NOT: v_max
; VI: v_mul_f32_e64 [[V:v[0-9]+]], 1.0, |[[V]]|
; GFX9: v_max_f32_e64 [[V:v[0-9]+]], |[[V]]|, |[[V]]|
; GCN: {{flat|global}}_store_dword v{{.+}}, [[V]]
define amdgpu_kernel void @test_fold_canonicalize_fabs_value_f32(ptr addrspace(1) %arg) {
%id = tail call i32 @llvm.amdgcn.workitem.id.x()
Expand Down
12 changes: 12 additions & 0 deletions llvm/test/Transforms/InstSimplify/fold-fadd-with-zero-gh154238.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
define float @src(float %arg1) {
; CHECK-LABEL: define float @src(
; CHECK-SAME: float [[ARG1:%.*]]) {
; CHECK-NEXT: [[V3:%.*]] = call float @llvm.fabs.f32(float [[ARG1]])
; CHECK-NEXT: ret float [[V3]]
;
%v2 = fadd float %arg1, 0.000000e+00
%v3 = call float @llvm.fabs.f32(float %v2)
ret float %v3
}