@@ -367,7 +367,8 @@ Error SYCLKernelFusion::fuseKernel(
367
367
DenseMap<std::pair<unsigned , unsigned >, unsigned > ParamMapping;
368
368
// The list of identical parameters is sorted, so the relevant entry can
369
369
// always only be the current front.
370
- SYCLKernelFusion::ParameterIdentity *ParamFront = ParamIdentities.begin ();
370
+ SYCLKernelFusion::ParameterIdentity *ParamFront = ParamIdentities.begin (),
371
+ *ParamEnd = ParamIdentities.end ();
371
372
unsigned FuncIndex = 0 ;
372
373
unsigned ArgIndex = 0 ;
373
374
for (const auto &Fused : FusedKernels) {
@@ -386,7 +387,7 @@ Error SYCLKernelFusion::fuseKernel(
386
387
SmallVector<bool , 8 > UsedArgsMask;
387
388
for (const auto &Arg : FF->args ()) {
388
389
int IdenticalIdx = -1 ;
389
- if (!ParamIdentities. empty () && FuncIndex == ParamFront->LHS .KernelIdx &&
390
+ if (ParamFront != ParamEnd && FuncIndex == ParamFront->LHS .KernelIdx &&
390
391
ParamIndex == ParamFront->LHS .ParamIdx ) {
391
392
// Because ParamIdentity is constructed such that LHS > RHS, the other
392
393
// parameter must already have been processed.
@@ -620,7 +621,7 @@ void SYCLKernelFusion::canonicalizeParameters(
620
621
// The input is a list of parameter pairs which werde detected to be
621
622
// identical. Each pair is constructed such that the RHS belongs to a kernel
622
623
// occuring before the kernel for the LHS in the list of kernels to fuse. This
623
- // means, that we want to use the LHS parameter instead of the RHS parameter.
624
+ // means, that we want to use the RHS parameter instead of the LHS parameter.
624
625
625
626
// In the first step we sort the list of pairs by their LHS.
626
627
std::sort (Params.begin (), Params.end ());
@@ -639,8 +640,7 @@ void SYCLKernelFusion::canonicalizeParameters(
639
640
// LHS and RHS are identical - this does not provide
640
641
// any useful information at all, discard it.
641
642
I = Params.erase (I);
642
- }
643
- if (Identities.count (I->LHS )) {
643
+ } else if (Identities.count (I->LHS )) {
644
644
// Duplicate
645
645
auto ExistingIdentity = Identities.at (I->LHS );
646
646
Identities.emplace (I->RHS , ExistingIdentity);
0 commit comments