@@ -4619,19 +4619,29 @@ namespace IGC
46194619 pattern->sources [1 ] = GetSource (s1, false , false , IsSourceOfSample (&I));
46204620 pattern->sources [2 ] = GetSource (s2, false , false , IsSourceOfSample (&I));
46214621
4622- // BFN can use imm16 in src0 and src2, check for those;
4622+ // BFN can use imm16 in src0 and src2 (not src1).
4623+ // Directly pass such immediates (or when lossless conversion is possible);
46234624 // otherwise try to add to constant pool even int32.
4624- if (dyn_cast<ConstantInt>(s0) && !s0-> getType ()-> isIntegerTy ( 16 ) )
4625+ if (ConstantInt *CI = dyn_cast<ConstantInt>(s0))
46254626 {
4626- AddToConstantPool (I.getParent (), s0); pattern->sources [0 ].fromConstantPool = true ;
4627+ if (!s0->getType ()->isIntegerTy (16 ) && !CI->getValue ().isIntN (16 ))
4628+ {
4629+ AddToConstantPool (I.getParent (), s0);
4630+ pattern->sources [0 ].fromConstantPool = true ;
4631+ }
46274632 }
46284633 if (dyn_cast<ConstantInt>(s1))
46294634 {
4630- AddToConstantPool (I.getParent (), s1); pattern->sources [1 ].fromConstantPool = true ;
4635+ AddToConstantPool (I.getParent (), s1);
4636+ pattern->sources [1 ].fromConstantPool = true ;
46314637 }
4632- if (dyn_cast<ConstantInt>(s2) && !s2-> getType ()-> isIntegerTy ( 16 ))
4638+ if (ConstantInt *CI = dyn_cast<ConstantInt>(s2))
46334639 {
4634- AddToConstantPool (I.getParent (), s2); pattern->sources [2 ].fromConstantPool = true ;
4640+ if (!s2->getType ()->isIntegerTy (16 ) && !CI->getValue ().isIntN (16 ))
4641+ {
4642+ AddToConstantPool (I.getParent (), s2);
4643+ pattern->sources [2 ].fromConstantPool = true ;
4644+ }
46354645 }
46364646
46374647 AddPattern (pattern);
0 commit comments