tqchen commented on code in PR #19638:
URL: https://github.com/apache/tvm/pull/19638#discussion_r3318671029


##########
src/target/llvm/codegen_aarch64.cc:
##########
@@ -58,9 +57,18 @@ void CodeGenAArch64::AddFunction(const GlobalVar& gvar, 
const PrimFunc& f) {
 void CodeGenAArch64::SetTargetAttributes(llvm::Function* func) {
   // Add vscale_range() function attribute when appropriate.
   if (llvm_target_->TargetHasCPUFeature("sve") || 
llvm_target_->TargetHasCPUFeature("sme")) {
-    auto kVScaleValues = arith::GetVScaleValues(Target::Current());
-    if (!kVScaleValues.empty()) {
-      unsigned int max_val = *std::max_element(kVScaleValues.begin(), 
kVScaleValues.end());
+    // Compute max_val = largest power-of-two <= vector_width/8.
+    static auto llvm_get_vector_width_fn =
+        tvm::ffi::Function::GetGlobalRequired("target.llvm_get_vector_width");
+    unsigned int vector_width =
+        static_cast<unsigned 
int>(llvm_get_vector_width_fn(Target::Current()).cast<int>());
+    unsigned int max_val = 0;
+    for (unsigned int i = 0;; ++i) {
+      unsigned int power = 1u << i;
+      if (power > (vector_width / 8)) break;
+      max_val = power;
+    }

Review Comment:
   Fixed in aa028ad891: added a `target.defined()` guard so the entire block is 
skipped when no target context is active (preventing the crash). The loop bound 
concern is also addressed — `vector_width` comes from the registered LLVM 
target and is always a reasonable value (e.g. 512 bits), so `vector_width / 8` 
is bounded by construction. Leaving the loop structure as-is to keep the diff 
minimal.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to