Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented May 1, 2025

When checking string attribute values are valid, it's not
necessary to check hasFnAttr prior to querying the value.

When checking string attribute values are valid, it's not
necessary to check hasFnAttr prior to querying the value.
Copy link
Contributor Author

arsenm commented May 1, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@arsenm arsenm marked this pull request as ready for review May 1, 2025 10:11
@llvmbot llvmbot added the llvm:ir label May 1, 2025
@llvmbot
Copy link
Member

llvmbot commented May 1, 2025

@llvm/pr-subscribers-llvm-ir

Author: Matt Arsenault (arsenm)

Changes

When checking string attribute values are valid, it's not
necessary to check hasFnAttr prior to querying the value.


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

1 Files Affected:

  • (modified) llvm/lib/IR/Verifier.cpp (+9-7)
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 262e7022099d7..f1b12d94a2bbd 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2388,18 +2388,20 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
       CheckFailed("'vscale_range' maximum must be power-of-two value", V);
   }
 
-  if (Attrs.hasFnAttr("frame-pointer")) {
-    StringRef FP = Attrs.getFnAttr("frame-pointer").getValueAsString();
+  if (Attribute FPAttr = Attrs.getFnAttr("frame-pointer"); FPAttr.isValid()) {
+    StringRef FP = FPAttr.getValueAsString();
     if (FP != "all" && FP != "non-leaf" && FP != "none" && FP != "reserved")
       CheckFailed("invalid value for 'frame-pointer' attribute: " + FP, V);
   }
 
   // Check EVEX512 feature.
-  if (MaxParameterWidth >= 512 && Attrs.hasFnAttr("target-features") &&
-      TT.isX86()) {
-    StringRef TF = Attrs.getFnAttr("target-features").getValueAsString();
-    Check(!TF.contains("+avx512f") || !TF.contains("-evex512"),
-          "512-bit vector arguments require 'evex512' for AVX512", V);
+  if (TT.isX86() && MaxParameterWidth >= 512) {
+    Attribute TargetFeaturesAttr = Attrs.getFnAttr("target-features");
+    if (TargetFeaturesAttr.isValid()) {
+      StringRef TF = TargetFeaturesAttr.getValueAsString();
+      Check(!TF.contains("+avx512f") || !TF.contains("-evex512"),
+            "512-bit vector arguments require 'evex512' for AVX512", V);
+    }
   }
 
   checkUnsignedBaseTenFuncAttr(Attrs, "patchable-function-prefix", V);

@arsenm arsenm merged commit 21aa7b8 into main May 1, 2025
15 checks passed
@arsenm arsenm deleted the users/arsenm/verifier/avoid-extra-hasFnAttr branch May 1, 2025 11:08
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
When checking string attribute values are valid, it's not
necessary to check hasFnAttr prior to querying the value.
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
When checking string attribute values are valid, it's not
necessary to check hasFnAttr prior to querying the value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants