[PATCH] D148236: ValueTracking: Handle constrained_sqrt in computeKnownFPClass

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 13 08:09:24 PDT 2023


arsenm created this revision.
arsenm added reviewers: jcranmer-intel, foad, kpn, sepavloff, andrew.w.kaylor, cameron.mcinally.
Herald added subscribers: StephenFan, okura, kuter, hiraditya.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added a project: LLVM.

With this, the body of CannotBeNegativeZero can be dropped.
Dropped the rounding mode restriction the current implementation has,
The standard text is pretty definitive about the sign of sqrt.


https://reviews.llvm.org/D148236

Files:
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/test/Transforms/Attributor/nofpclass.ll


Index: llvm/test/Transforms/Attributor/nofpclass.ll
===================================================================
--- llvm/test/Transforms/Attributor/nofpclass.ll
+++ llvm/test/Transforms/Attributor/nofpclass.ll
@@ -14,6 +14,7 @@
 declare i1 @llvm.is.fpclass.f32(float, i32 immarg)
 declare float @llvm.experimental.constrained.sitofp.f32.i32(i32, metadata, metadata)
 declare float @llvm.experimental.constrained.uitofp.f32.i32(i32, metadata, metadata)
+declare float @llvm.experimental.constrained.sqrt.f32(float, metadata, metadata)
 
 define float @returned_0() {
 ; CHECK-LABEL: define noundef nofpclass(nan inf nzero sub norm) float @returned_0() {
@@ -1185,3 +1186,58 @@
   %val = call float @llvm.experimental.constrained.uitofp.f32.i32(i32 %arg, metadata !"round.dynamic", metadata !"fpexcept.strict")
   ret float %val
 }
+
+define float @constrained_sqrt(float %arg) strictfp {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind strictfp willreturn memory(inaccessiblemem: readwrite)
+; CHECK-LABEL: define nofpclass(ninf nsub nnorm) float @constrained_sqrt
+; CHECK-SAME: (float [[ARG:%.*]]) #[[ATTR5]] {
+; CHECK-NEXT:    [[VAL:%.*]] = call nofpclass(ninf nsub nnorm) float @llvm.experimental.constrained.sqrt.f32(float [[ARG]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR7]]
+; CHECK-NEXT:    ret float [[VAL]]
+;
+  %val = call float @llvm.experimental.constrained.sqrt.f32(float %arg, metadata !"round.dynamic", metadata !"fpexcept.strict")
+  ret float %val
+}
+
+define float @constrained_sqrt_nonan(float nofpclass(nan) %arg) strictfp {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind strictfp willreturn memory(inaccessiblemem: readwrite)
+; CHECK-LABEL: define nofpclass(ninf nsub nnorm) float @constrained_sqrt_nonan
+; CHECK-SAME: (float nofpclass(nan) [[ARG:%.*]]) #[[ATTR5]] {
+; CHECK-NEXT:    [[VAL:%.*]] = call nofpclass(ninf nsub nnorm) float @llvm.experimental.constrained.sqrt.f32(float nofpclass(nan) [[ARG]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR7]]
+; CHECK-NEXT:    ret float [[VAL]]
+;
+  %val = call float @llvm.experimental.constrained.sqrt.f32(float %arg, metadata !"round.dynamic", metadata !"fpexcept.strict")
+  ret float %val
+}
+
+define float @constrained_sqrt_nopinf(float nofpclass(pinf) %arg) strictfp {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind strictfp willreturn memory(inaccessiblemem: readwrite)
+; CHECK-LABEL: define nofpclass(inf nsub nnorm) float @constrained_sqrt_nopinf
+; CHECK-SAME: (float nofpclass(pinf) [[ARG:%.*]]) #[[ATTR5]] {
+; CHECK-NEXT:    [[VAL:%.*]] = call nofpclass(inf nsub nnorm) float @llvm.experimental.constrained.sqrt.f32(float nofpclass(pinf) [[ARG]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR7]]
+; CHECK-NEXT:    ret float [[VAL]]
+;
+  %val = call float @llvm.experimental.constrained.sqrt.f32(float %arg, metadata !"round.dynamic", metadata !"fpexcept.strict")
+  ret float %val
+}
+
+define float @constrained_sqrt_nonegzero(float nofpclass(nzero) %arg) strictfp {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind strictfp willreturn memory(inaccessiblemem: readwrite)
+; CHECK-LABEL: define nofpclass(ninf nzero nsub nnorm) float @constrained_sqrt_nonegzero
+; CHECK-SAME: (float nofpclass(nzero) [[ARG:%.*]]) #[[ATTR5]] {
+; CHECK-NEXT:    [[VAL:%.*]] = call nofpclass(ninf nzero nsub nnorm) float @llvm.experimental.constrained.sqrt.f32(float nofpclass(nzero) [[ARG]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR7]]
+; CHECK-NEXT:    ret float [[VAL]]
+;
+  %val = call float @llvm.experimental.constrained.sqrt.f32(float %arg, metadata !"round.dynamic", metadata !"fpexcept.strict")
+  ret float %val
+}
+
+define float @constrained_sqrt_nozero(float nofpclass(zero) %arg) strictfp {
+; CHECK: Function Attrs: nofree norecurse nosync nounwind strictfp willreturn memory(inaccessiblemem: readwrite)
+; CHECK-LABEL: define nofpclass(ninf nzero nsub nnorm) float @constrained_sqrt_nozero
+; CHECK-SAME: (float nofpclass(zero) [[ARG:%.*]]) #[[ATTR5]] {
+; CHECK-NEXT:    [[VAL:%.*]] = call nofpclass(ninf nzero nsub nnorm) float @llvm.experimental.constrained.sqrt.f32(float nofpclass(zero) [[ARG]], metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR7]]
+; CHECK-NEXT:    ret float [[VAL]]
+;
+  %val = call float @llvm.experimental.constrained.sqrt.f32(float %arg, metadata !"round.dynamic", metadata !"fpexcept.strict")
+  ret float %val
+}
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -4222,7 +4222,8 @@
         Known.copysign(KnownSign);
         break;
       }
-      case Intrinsic::sqrt: {
+      case Intrinsic::sqrt:
+      case Intrinsic::experimental_constrained_sqrt: {
         KnownFPClass KnownSrc;
         computeKnownFPClass(II->getArgOperand(0), DemandedElts,
                             InterestedClasses, KnownSrc, Depth + 1, Q, TLI);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148236.513241.patch
Type: text/x-patch
Size: 5047 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230413/e5e73907/attachment.bin>


More information about the llvm-commits mailing list