@@ -4027,34 +4027,23 @@ LLVM_Util::op_1st_active_lane_of(llvm::Value* mask)
40274027 // Assumes mask is not empty
40284028
40294029 llvm::Type* intMaskType = nullptr ;
4030+ llvm::Value* int_mask = nullptr ;
40304031 switch (m_vector_width) {
40314032 case 16 :
40324033 // We can just reinterpret cast a 16 bit mask to a 16 bit integer
40334034 // and all types are happy
40344035 intMaskType = type_int16 ();
4036+ int_mask = builder ().CreateBitCast (mask, intMaskType);
40354037 break ;
40364038 case 8 :
40374039 // We can just reinterpret cast a 8 bit mask to a 8 bit integer
40384040 // and all types are happy
40394041 intMaskType = type_int8 ();
4042+ int_mask = builder ().CreateBitCast (mask, intMaskType);
40404043 break ;
40414044 case 4 : {
40424045 intMaskType = type_int8 ();
4043-
4044- llvm::Value* mask_as_int = mask4_as_int8 (mask);
4045-
4046- // Count trailing zeros, least significant
4047- llvm::Type* types[] = { intMaskType };
4048- llvm::Function* func_cttz
4049- = llvm::Intrinsic::getDeclaration (module (), llvm::Intrinsic::cttz,
4050- toArrayRef (types));
4051-
4052- llvm::Value* args[2 ] = { mask_as_int, constant_bool (true ) };
4053-
4054- llvm::Value* firstNonZeroIndex = builder ().CreateCall (func_cttz,
4055- toArrayRef (args));
4056- return firstNonZeroIndex;
4057-
4046+ int_mask = mask4_as_int8 (mask);
40584047 break ;
40594048 }
40604049 default : OSL_ASSERT (0 && " unsupported native bit mask width" );
@@ -4066,8 +4055,7 @@ LLVM_Util::op_1st_active_lane_of(llvm::Value* mask)
40664055 = llvm::Intrinsic::getDeclaration (module (), llvm::Intrinsic::cttz,
40674056 toArrayRef (types));
40684057
4069- llvm::Value* int_mask = builder ().CreateBitCast (mask, intMaskType);
4070- llvm::Value* args[2 ] = { int_mask, constant_bool (true ) };
4058+ llvm::Value* args[2 ] = { int_mask, constant_bool (true ) };
40714059
40724060 llvm::Value* firstNonZeroIndex = builder ().CreateCall (func_cttz,
40734061 toArrayRef (args));
0 commit comments