[llvm] 3a503a4 - [x86] fix miscompile from wrongly identified fneg
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 1 06:56:49 PDT 2022
Author: Sanjay Patel
Date: 2022-06-01T09:56:33-04:00
New Revision: 3a503a4a9c1fa04020a8c64524234ea0269f80bd
URL: https://github.com/llvm/llvm-project/commit/3a503a4a9c1fa04020a8c64524234ea0269f80bd
DIFF: https://github.com/llvm/llvm-project/commit/3a503a4a9c1fa04020a8c64524234ea0269f80bd.diff
LOG: [x86] fix miscompile from wrongly identified fneg
We may need to peek through a bitcast when identifying an fneg idiom
via its pool constant, but we can't allow a different-sized constant
in that match.
This is noted in issue #55758 with an example that needs fast-math,
but as the test here shows, this has potential to miscompile more
generally (no fast-math required).
Differential Revision: https://reviews.llvm.org/D126775
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/neg_fp.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index c2c93cf033f9..aa21b4533be1 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -50129,10 +50129,14 @@ static SDValue isFNEG(SelectionDAG &DAG, SDNode *N, unsigned Depth = 0) {
if (!UndefElts[I] && !EltBits[I].isSignMask())
return SDValue();
- return peekThroughBitcasts(Op0);
+ // Only allow bitcast from correctly-sized constant.
+ Op0 = peekThroughBitcasts(Op0);
+ if (Op0.getScalarValueSizeInBits() == ScalarSize)
+ return Op0;
}
- }
- }
+ break;
+ } // case
+ } // switch
return SDValue();
}
diff --git a/llvm/test/CodeGen/X86/neg_fp.ll b/llvm/test/CodeGen/X86/neg_fp.ll
index 1d7260a8e78e..96af17367aa3 100644
--- a/llvm/test/CodeGen/X86/neg_fp.ll
+++ b/llvm/test/CodeGen/X86/neg_fp.ll
@@ -82,11 +82,13 @@ define float @fdiv_extra_use_changes_cost(float %a0, float %a1, float %a2) nounw
ret float %div5
}
-; FIXME: PR55758 - this is not -(-X)
+; PR55758 - this is not -(-X)
define <2 x i64> @fneg_mismatched_sizes(<4 x float> %x) {
; CHECK-LABEL: fneg_mismatched_sizes:
; CHECK: # %bb.0:
+; CHECK-NEXT: xorps {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0
+; CHECK-NEXT: xorps {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0
; CHECK-NEXT: retl
%n = fneg <4 x float> %x
%b = bitcast <4 x float> %n to <2 x i64>
More information about the llvm-commits
mailing list