From 44accc6bce65bda917979385fd8b865c68ec58c6 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Tue, 15 Oct 2024 13:19:11 +0800 Subject: [PATCH 1/4] [Verifier] Verify attribute `denormal-fp-math[-f32]` --- llvm/lib/IR/Verifier.cpp | 19 ++++++++++++++++++ llvm/test/CodeGen/AMDGPU/clamp-modifier.ll | 2 +- .../DebugInfo/COFF/fortran-contained-proc.ll | 4 ++-- .../Attributor/nofpclass-minimum-maximum.ll | 2 +- .../Attributor/nofpclass-minnum-maxnum.ll | 2 +- .../InstCombine/fcmp-denormals-are-zero.ll | 2 +- llvm/test/Verifier/denormal-fp-math.ll | 20 +++++++++++++++++++ 7 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 llvm/test/Verifier/denormal-fp-math.ll diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index b89c9ce46e7d6..e9f8ef831e5a1 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 45324392aacde..bafbc9486a1c2 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 f8b66aae212e7..82b39d4fa34cb 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 f60581c0089af..d9b1375d3c633 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 cea11a3c58e3c..ddfddbc22a517 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 22c422c816039..eea1dda6230a9 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 0000000000000..f9d778b460db9 --- /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 +} From 0848fc0be808fcb7ed953e6e7cbeb937b42af4d2 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Tue, 15 Oct 2024 14:10:46 +0800 Subject: [PATCH 2/4] [Verifier] Address reviewe comments. NFC. --- llvm/lib/IR/Verifier.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index e9f8ef831e5a1..0412b93798b94 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2402,21 +2402,15 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, 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)) + if (!parseDenormalFPAttribute(S).isValid()) 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)) + if (!parseDenormalFPAttribute(S).isValid()) CheckFailed("invalid value for 'denormal-fp-math-f32' attribute: " + S, V); } From f237ec04189796ef29e3856eec225800ca1e5f73 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Tue, 15 Oct 2024 14:23:51 +0800 Subject: [PATCH 3/4] [Verifier] Address review comments. NFC. --- llvm/test/Verifier/denormal-fp-math.ll | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/test/Verifier/denormal-fp-math.ll b/llvm/test/Verifier/denormal-fp-math.ll index f9d778b460db9..76aaf88850c99 100644 --- a/llvm/test/Verifier/denormal-fp-math.ll +++ b/llvm/test/Verifier/denormal-fp-math.ll @@ -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 define float @test_denormal_fp_math_valid() "denormal-fp-math"="ieee,ieee" { ret float 1.0 } From c14b0bb174d5a1fcd3d1e80955628dc87e4db35d Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Tue, 15 Oct 2024 15:10:02 +0800 Subject: [PATCH 4/4] [Verifier] Use `--implicit-check-not` --- llvm/test/Verifier/denormal-fp-math.ll | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llvm/test/Verifier/denormal-fp-math.ll b/llvm/test/Verifier/denormal-fp-math.ll index 76aaf88850c99..f79f28a366944 100644 --- a/llvm/test/Verifier/denormal-fp-math.ll +++ b/llvm/test/Verifier/denormal-fp-math.ll @@ -1,6 +1,5 @@ -; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s +; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck --implicit-check-not="invalid value" %s -; CHECK-NOT: invalid value for 'denormal-fp-math' attribute define float @test_denormal_fp_math_valid() "denormal-fp-math"="ieee,ieee" { ret float 1.0 }