[llvm] 21aa7b8 - Verifier: Avoid unnecessary hasFnAttr (#138104)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 1 04:08:42 PDT 2025


Author: Matt Arsenault
Date: 2025-05-01T13:08:39+02:00
New Revision: 21aa7b8138a140514ea90d85bf86c57de68c6d4f

URL: https://github.com/llvm/llvm-project/commit/21aa7b8138a140514ea90d85bf86c57de68c6d4f
DIFF: https://github.com/llvm/llvm-project/commit/21aa7b8138a140514ea90d85bf86c57de68c6d4f.diff

LOG: Verifier: Avoid unnecessary hasFnAttr (#138104)

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

Added: 
    

Modified: 
    llvm/lib/IR/Verifier.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 28ba944d8ede3..7d1918e175c0c 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);


        


More information about the llvm-commits mailing list