[llvm] [LV] Vectorize early exit loops with multiple exits. (PR #174864)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 13 20:57:41 PST 2026


lukel97 wrote:

> I'm moving my comment from the commit over here to the PR, gives better context I think.
> 
> I see this failure from libstdc++ with `_GLIBCXX_DEBUG` enabled and I suspect it came from the commit from this PR.
> 
> ```
>  In function:                                                                                         
>       void std::sort(_RandomAccessIterator, _RandomAccessIterator, _Compare)                           
>       [_RandomAccessIterator = EarlyExitInfo *, _Compare = (lambda at                                  
>       /local/mnt/workspace/bcain-20260213_180548/llvm-project/llvm/lib/Transforms/Vectorize/VPlanTrans 
>   forms.c                                                                                              
>   pp:4082:21)]                                                                                         
>                                                                                                        
>   Error: comparison doesn't meet irreflexive requirements, assert(!(a < a)).                           
>                                                                                                        
>   Objects involved in the operation:                                                                   
>       instance "functor" @ 0x7ffc58648430 {                                                            
>       }                                                                                                
>       iterator::value_type "ordered type"  {                                                           
>       }                  
> ```
> 
> Here's a possible fix to make the comparator pass the irreflexive requirement?
> 
> ```
> --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp                                                    
> +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
> @@ -4080,7 +4080,8 @@ void VPlanTransforms::handleUncountableEarlyExits(VPlan &Plan,                       
>    assert(!Exits.empty() && "must have at least one early exit");                                          
>    // Sort exits by dominance to get the correct program order.                                            
>    llvm::sort(Exits, [&VPDT](const EarlyExitInfo &A, const EarlyExitInfo &B) {                             
> -    return VPDT.dominates(A.EarlyExitingVPBB, B.EarlyExitingVPBB);                                        
> +    return A.EarlyExitingVPBB != B.EarlyExitingVPBB &&                                                    
> +           VPDT.dominates(A.EarlyExitingVPBB, B.EarlyExitingVPBB);                                        
>    });                                                                                                     
> ```
> 
> ... I'll follow up w/a reproducer when my batch run is over ~tonight or tomorrow.

I think we can use VPDT.properlyDominates(A.EarlyExitingVPBB, B.EarlyExitingVPBB) too to meet the irreflexive requirement

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


More information about the llvm-commits mailing list