[PATCH] D126775: [x86] fix miscompile from wrongly identified fneg
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 1 05:51:36 PDT 2022
spatel created this revision.
spatel added reviewers: RKSimon, pengfei, craig.topper.
Herald added subscribers: jsji, StephenFan, hiraditya, mcrosier.
Herald added a project: All.
spatel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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 <https://github.com/llvm/llvm-project/issues/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).
https://reviews.llvm.org/D126775
Files:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/neg_fp.ll
Index: llvm/test/CodeGen/X86/neg_fp.ll
===================================================================
--- llvm/test/CodeGen/X86/neg_fp.ll
+++ llvm/test/CodeGen/X86/neg_fp.ll
@@ -82,11 +82,13 @@
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>
Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -50129,10 +50129,14 @@
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();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126775.433366.patch
Type: text/x-patch
Size: 1240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220601/e857eba0/attachment.bin>
More information about the llvm-commits
mailing list