[llvm] [LV] Check loop-preheader for loop-legality when pass-remarks enabled (PR #166310)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 6 03:22:29 PST 2025


================
@@ -795,6 +795,14 @@ static bool canWidenCallReturnType(Type *Ty) {
 bool LoopVectorizationLegality::canVectorizeInstrs() {
   BasicBlock *Header = TheLoop->getHeader();
 
+  /// Generally, if `TheLoop` lacks a PreHeader, it won't reach this point.
+  /// However, when executed with remarks options like `-pass-remarks=vector`
+  /// it will reach here to output extra debug messages, so need to check.
+  /// Additionally, before reaching here, the debug messages would have
+  /// included `Loop doesn't have a legal pre-header`, so we omit that.
+  if (ORE->allowExtraAnalysis(DEBUG_TYPE) && !TheLoop->getLoopPreheader())
+    return false;
----------------
fhahn wrote:

Checking here means we will miss out on any extra analysis for subsequent instructions.

We should be able to check in IVDescriptor and bail out if there's no preheader there, which would still allow continuing with the other checks.

You can add an unvectorizable instruction to the function, perhaps something like an unsupported call, for which we should get a missed remark ideally, even if there's no preheader.

https://github.com/llvm/llvm-project/pull/166310


More information about the llvm-commits mailing list