Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/coreclr/jit/ifconversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,10 @@ GenTree* OptIfConversionDsc::TrySelectToCnsOpCond(GenTreeConditional* select)
}
return retCond;
}
else if (trueVal == falseVal)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why here instead of gtFoldExpr so that we avoid ending up with such conditional select nodes in the first place?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how I am supposed to improve gtFoldExpr to handle this.
We enter if-conversion with IR equivalent to:

if (a == b)
{
    result = false;
}
else
{
    result = false;
}

return result;

where a and b are of type double so can't be folded. I am folding based on the true/false paths storing the same values, but that first requires the necessary control flow simplification which if conversion does to collapse this into a single SELECT which can then be analysed. Doesn't look like a gtFoldExpr job to me. Although there might be some opportunity very early on. Anyway I think we should have this either way.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was asking why have this logic here rather than general folding done on the produced GT_SELECT node.

That way it consistently gets optimized, with you being able to effectively just do GenTree* select = ...; return gtFoldExpr(select) as what if conversion produces -- it's notably how we handle such things in import and other phases as well

{
return m_compiler->gtWrapWithSideEffects(trueInput, cond);
}

#ifdef TARGET_RISCV64
bool isCondReversed = false;
Expand Down
Loading