Skip to content

[Verifier] Verify attribute denormal-fp-math[-f32] #112310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 15, 2024

Conversation

dtcxzyw
Copy link
Member

@dtcxzyw dtcxzyw commented Oct 15, 2024

Some typos are also fixed. Address #112067 (review).

@llvmbot
Copy link
Member

llvmbot commented Oct 15, 2024

@llvm/pr-subscribers-llvm-transforms
@llvm/pr-subscribers-debuginfo

@llvm/pr-subscribers-backend-amdgpu

Author: Yingwei Zheng (dtcxzyw)

Changes

Some typos are also fixed. Address #112067 (review).


Full diff: https://github.com/llvm/llvm-project/pull/112310.diff

7 Files Affected:

  • (modified) llvm/lib/IR/Verifier.cpp (+19)
  • (modified) llvm/test/CodeGen/AMDGPU/clamp-modifier.ll (+1-1)
  • (modified) llvm/test/DebugInfo/COFF/fortran-contained-proc.ll (+2-2)
  • (modified) llvm/test/Transforms/Attributor/nofpclass-minimum-maximum.ll (+1-1)
  • (modified) llvm/test/Transforms/Attributor/nofpclass-minnum-maxnum.ll (+1-1)
  • (modified) llvm/test/Transforms/InstCombine/fcmp-denormals-are-zero.ll (+1-1)
  • (added) llvm/test/Verifier/denormal-fp-math.ll (+20)
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index b89c9ce46e7d61..e9f8ef831e5a13 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2401,6 +2401,25 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
     if (!Info)
       CheckFailed("invalid name for a VFABI variant: " + S, V);
   }
+
+  auto IsValidDenormalMode = [](StringRef S) {
+    DenormalMode Denormals = parseDenormalFPAttribute(S);
+    return Denormals.Input != DenormalMode::Invalid &&
+           Denormals.Output != DenormalMode::Invalid;
+  };
+
+  if (auto A = Attrs.getFnAttr("denormal-fp-math"); A.isValid()) {
+    StringRef S = A.getValueAsString();
+    if (!IsValidDenormalMode(S))
+      CheckFailed("invalid value for 'denormal-fp-math' attribute: " + S, V);
+  }
+
+  if (auto A = Attrs.getFnAttr("denormal-fp-math-f32"); A.isValid()) {
+    StringRef S = A.getValueAsString();
+    if (!IsValidDenormalMode(S))
+      CheckFailed("invalid value for 'denormal-fp-math-f32' attribute: " + S,
+                  V);
+  }
 }
 
 void Verifier::verifyFunctionMetadata(
diff --git a/llvm/test/CodeGen/AMDGPU/clamp-modifier.ll b/llvm/test/CodeGen/AMDGPU/clamp-modifier.ll
index 45324392aacde2..bafbc9486a1c21 100644
--- a/llvm/test/CodeGen/AMDGPU/clamp-modifier.ll
+++ b/llvm/test/CodeGen/AMDGPU/clamp-modifier.ll
@@ -1657,7 +1657,7 @@ declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1
 
 attributes #0 = { nounwind "denormal-fp-math-f32"="preserve-sign,preserve-sign" }
 attributes #1 = { nounwind readnone }
-attributes #2 = { nounwind "denormal-fp-math-f32"="ieee.ieee" }
+attributes #2 = { nounwind "denormal-fp-math-f32"="ieee,ieee" }
 attributes #3 = { nounwind "denormal-fp-math-f32"="ieee,ieee" "denormal-fp-math"="preserve-sign,preserve-sign" }
 
 !llvm.dbg.cu = !{!0}
diff --git a/llvm/test/DebugInfo/COFF/fortran-contained-proc.ll b/llvm/test/DebugInfo/COFF/fortran-contained-proc.ll
index f8b66aae212e79..82b39d4fa34cb0 100644
--- a/llvm/test/DebugInfo/COFF/fortran-contained-proc.ll
+++ b/llvm/test/DebugInfo/COFF/fortran-contained-proc.ll
@@ -74,8 +74,8 @@ declare void @llvm.dbg.declare(metadata, metadata, metadata) #3
 ; Function Attrs: mustprogress nofree nosync nounwind readnone speculatable willreturn
 declare void @llvm.dbg.value(metadata, metadata, metadata) #3
 
-attributes #0 = { nounwind uwtable "denormal-fp-math"="preserve_sign,preserve_sign" "frame-pointer"="none" "intel-lang"="fortran" "min-legal-vector-width"="0" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" }
-attributes #1 = { mustprogress nofree norecurse nosync nounwind uwtable willreturn writeonly "denormal-fp-math"="preserve_sign,preserve_sign" "frame-pointer"="none" "intel-lang"="fortran" "min-legal-vector-width"="0" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" }
+attributes #0 = { nounwind uwtable "denormal-fp-math"="preserve-sign,preserve-sign" "frame-pointer"="none" "intel-lang"="fortran" "min-legal-vector-width"="0" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" }
+attributes #1 = { mustprogress nofree norecurse nosync nounwind uwtable willreturn writeonly "denormal-fp-math"="preserve-sign,preserve-sign" "frame-pointer"="none" "intel-lang"="fortran" "min-legal-vector-width"="0" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" }
 attributes #2 = { nofree "intel-lang"="fortran" }
 attributes #3 = { mustprogress nofree nosync nounwind readnone speculatable willreturn }
 attributes #4 = { nounwind }
diff --git a/llvm/test/Transforms/Attributor/nofpclass-minimum-maximum.ll b/llvm/test/Transforms/Attributor/nofpclass-minimum-maximum.ll
index f60581c0089afe..d9b1375d3c6337 100644
--- a/llvm/test/Transforms/Attributor/nofpclass-minimum-maximum.ll
+++ b/llvm/test/Transforms/Attributor/nofpclass-minimum-maximum.ll
@@ -511,6 +511,6 @@ attributes #3 = { "denormal-fp-math"="dynamic,dynamic" }
 attributes #4 = { "denormal-fp-math"="ieee,preserve-sign" }
 attributes #5 = { "denormal-fp-math"="preserve-sign,ieee" }
 attributes #6 = { "denormal-fp-math"="ieee,positive-zero" }
-attributes #7 = { "denormal-fp-math"="positive-zero-sign,ieee" }
+attributes #7 = { "denormal-fp-math"="positive-zero,ieee" }
 ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
 ; TUNIT: {{.*}}
diff --git a/llvm/test/Transforms/Attributor/nofpclass-minnum-maxnum.ll b/llvm/test/Transforms/Attributor/nofpclass-minnum-maxnum.ll
index cea11a3c58e3c4..ddfddbc22a5179 100644
--- a/llvm/test/Transforms/Attributor/nofpclass-minnum-maxnum.ll
+++ b/llvm/test/Transforms/Attributor/nofpclass-minnum-maxnum.ll
@@ -511,6 +511,6 @@ attributes #3 = { "denormal-fp-math"="dynamic,dynamic" }
 attributes #4 = { "denormal-fp-math"="ieee,preserve-sign" }
 attributes #5 = { "denormal-fp-math"="preserve-sign,ieee" }
 attributes #6 = { "denormal-fp-math"="ieee,positive-zero" }
-attributes #7 = { "denormal-fp-math"="positive-zero-sign,ieee" }
+attributes #7 = { "denormal-fp-math"="positive-zero,ieee" }
 ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
 ; TUNIT: {{.*}}
diff --git a/llvm/test/Transforms/InstCombine/fcmp-denormals-are-zero.ll b/llvm/test/Transforms/InstCombine/fcmp-denormals-are-zero.ll
index 22c422c8160395..eea1dda6230a9d 100644
--- a/llvm/test/Transforms/InstCombine/fcmp-denormals-are-zero.ll
+++ b/llvm/test/Transforms/InstCombine/fcmp-denormals-are-zero.ll
@@ -350,5 +350,5 @@ declare <2 x double> @llvm.fabs.v2f64(<2 x double>)
 
 attributes #0 = { "denormal-fp-math"="ieee,preserve-sign" }
 attributes #1 = { "denormal-fp-math"="ieee,positive-zero" }
-attributes #2 = { "denormal-fp-math"="ieee,iee" }
+attributes #2 = { "denormal-fp-math"="ieee,ieee" }
 attributes #3 = { "denormal-fp-math-f32"="ieee,preserve-sign" }
diff --git a/llvm/test/Verifier/denormal-fp-math.ll b/llvm/test/Verifier/denormal-fp-math.ll
new file mode 100644
index 00000000000000..f9d778b460db9b
--- /dev/null
+++ b/llvm/test/Verifier/denormal-fp-math.ll
@@ -0,0 +1,20 @@
+; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
+
+define float @test_denormal_fp_math_valid() "denormal-fp-math"="ieee,ieee" {
+  ret float 1.0
+}
+
+; CHECK: invalid value for 'denormal-fp-math' attribute: foo,ieee
+define float @test_denormal_fp_math_invalid1() "denormal-fp-math"="foo,ieee" {
+  ret float 1.0
+}
+
+; CHECK: invalid value for 'denormal-fp-math' attribute: ieee,ieee,ieee
+define float @test_denormal_fp_math_invalid2() "denormal-fp-math"="ieee,ieee,ieee" {
+  ret float 1.0
+}
+
+; CHECK: invalid value for 'denormal-fp-math-f32' attribute: foo,ieee
+define float @test_denormal_fp_math_f32_invalid() "denormal-fp-math-f32"="foo,ieee" {
+  ret float 1.0
+}

@@ -1,5 +1,6 @@
; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s

; CHECK-NOT: invalid value for 'denormal-fp-math' attribute
Copy link
Contributor

Choose a reason for hiding this comment

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

Too fragile negative check on exact string. Use implicit-check-not for the broadest error check. Or just delete the valid case, verifier tests usually don't include them (those go in test/Assembler)

@dtcxzyw dtcxzyw merged commit 8d8bb40 into llvm:main Oct 15, 2024
8 checks passed
@dtcxzyw dtcxzyw deleted the verify-denormal-fp branch October 15, 2024 09:32
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants