HomePhabricator

[CodeGen] recognize select form of and/ors when splitting branch conditions

Authored by aqjune on Dec 31 2020, 11:46 AM.

Description

[CodeGen] recognize select form of and/ors when splitting branch conditions

Recently a few patches are made to move towards using select i1 instead of and/or i1 to represent "a && b"/"a || b" in C/C++.
"a && b" in C/C++ does not evaluate b if a is false whereas 'and a, b' in IR evaluates b and uses its result regardless of the result of a.
This is problematic because it can cause miscompilation if b was an erroneous operation (https://llvm.org/pr48353).
In C/C++, the result is simply false because b is not evaluated, but in IR the result is poison.
The discussion at D93065 has more context about this.

This patch makes two branch-splitting optimizations (one in SelectionDAGBuilder, one in CodeGenPrepare) recognize
select form of and/or as well using m_LogicalAnd/Or.
Since it is CodeGen, I think this is semantically ok (at least as safe as what codegen already did).

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D93853

Details

Committed
aqjuneDec 31 2020, 11:46 AM
Reviewer
nikic
Differential Revision
D93853: [CodeGen] recognize select form of and/ors when splitting branch conditions
Parents
rG509fa8e02e25: [SCEV] recognize logical and/or pattern
Branches
Unknown
Tags
Unknown