[PATCH] D138331: ConstantFolding: Fix handling of canonicalize for ppc_fp128 0s

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 18 14:59:41 PST 2022


arsenm created this revision.
arsenm added reviewers: jcranmer-intel, spatel.
Herald added subscribers: shchenz, hiraditya.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

https://reviews.llvm.org/D138331

Files:
  llvm/lib/Analysis/ConstantFolding.cpp
  llvm/test/Transforms/InstSimplify/canonicalize.ll


Index: llvm/test/Transforms/InstSimplify/canonicalize.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/canonicalize.ll
+++ llvm/test/Transforms/InstSimplify/canonicalize.ll
@@ -593,6 +593,30 @@
   ret ppc_fp128 %ret
 }
 
+define ppc_fp128 @canonicalize_noncanonical_zero_0_ppcf128() {
+; CHECK-LABEL: @canonicalize_noncanonical_zero_0_ppcf128(
+; CHECK-NEXT:    ret ppc_fp128 0xM00000000000000000000000000000000
+;
+  %ret = call ppc_fp128 @llvm.canonicalize.ppcf128(ppc_fp128 0xM0000000000000000ffffffffffffffff)
+  ret ppc_fp128 %ret
+}
+
+define ppc_fp128 @canonicalize_noncanonical_zero_1_ppcf128() {
+; CHECK-LABEL: @canonicalize_noncanonical_zero_1_ppcf128(
+; CHECK-NEXT:    ret ppc_fp128 0xM00000000000000000000000000000000
+;
+  %ret = call ppc_fp128 @llvm.canonicalize.ppcf128(ppc_fp128 0xM00000000000000000000000000000001)
+  ret ppc_fp128 %ret
+}
+
+define ppc_fp128 @canonicalize_noncanonical_negzero_0_ppcf128() {
+; CHECK-LABEL: @canonicalize_noncanonical_negzero_0_ppcf128(
+; CHECK-NEXT:    ret ppc_fp128 0xM80000000000000000000000000000000
+;
+  %ret = call ppc_fp128 @llvm.canonicalize.ppcf128(ppc_fp128 0xM8000000000000000ffffffffffffffff)
+  ret ppc_fp128 %ret
+}
+
 define ppc_fp128 @canonicalize_inf_ppcf128() {
 ; CHECK-LABEL: @canonicalize_inf_ppcf128(
 ; CHECK-NEXT:    [[RET:%.*]] = call ppc_fp128 @llvm.canonicalize.ppcf128(ppc_fp128 0xM7FF00000000000000000000000000000)
Index: llvm/lib/Analysis/ConstantFolding.cpp
===================================================================
--- llvm/lib/Analysis/ConstantFolding.cpp
+++ llvm/lib/Analysis/ConstantFolding.cpp
@@ -1946,8 +1946,12 @@
 static Constant *constantFoldCanonicalize(const Type *Ty, const CallBase *CI,
                                           const APFloat &Src) {
   // Zero, positive and negative, is always OK to fold.
-  if (Src.isZero())
-    return ConstantFP::get(CI->getContext(), Src);
+  if (Src.isZero()) {
+    // Get a fresh 0, since ppc_fp128 does have non-canonical zeros.
+    return ConstantFP::get(
+        CI->getContext(),
+        APFloat::getZero(Src.getSemantics(), Src.isNegative()));
+  }
 
   if (!Ty->isIEEELikeFPTy())
     return nullptr;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138331.476608.patch
Type: text/x-patch
Size: 2226 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221118/cf0a3e51/attachment.bin>


More information about the llvm-commits mailing list