[llvm] [InstCombine] Fold canonicalized form of vecreduce_or(get_active_lane_mask) (PR #220085)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 03:43:14 PDT 2026


================
@@ -3581,6 +3581,22 @@ Instruction *InstCombinerImpl::foldICmpBitCast(ICmpInst &Cmp) {
     }
   }
 
+  // Fold the canonicalized form of vector_reduce_or if the arg is
+  // get_active_lane mask.
+  // icmp ne (bitcast <N x i1> to iN (get_active_lane_mask(l, h))), 0 ->
+  //            icmp ult l, h
+  // icmp eq (bitcast <N x i1> to iN (get_active_lane_mask(l, h))), 0 ->
+  //            icmp uge l, h
+  Value *Upper, *Lower;
+  if (match(BCSrcOp, m_Intrinsic<Intrinsic::get_active_lane_mask>(
+                         m_Value(Lower), m_Value(Upper))) &&
+      match(Op1, m_Zero())) {
----------------
paulwalker-arm wrote:

There's nothing here that specifically checks BCSrcOp is a scalar integer. For example, the pattern will incorrectly match:
```
define <2 x i1> @foo(i32 %a, i32 %b) {                
  %mask = call <32 x i1> @llvm.get.active.lane.mask.v32i1.i32(i32 %a, i32 %b)       
  %cast = bitcast <32 x i1> %mask to <2 x i16>                                      
  %red = icmp eq <2 x i16> %cast, zeroinitializer                                   
  ret <2 x i1> %red                                                                 
} 
```

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


More information about the llvm-commits mailing list