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

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 28 01:00:44 PST 2020


aqjune created this revision.
aqjune added reviewers: nikic, dmgreen, craig.topper, fhahn, lebedev.ri, spatel, gberry, aemerson.
Herald added a subscriber: hiraditya.
aqjune requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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 <https://reviews.llvm.org/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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93853

Files:
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/test/CodeGen/AArch64/arm64_32.ll
  llvm/test/CodeGen/AArch64/fast-isel-branch-cond-split.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93853.313833.patch
Type: text/x-patch
Size: 11103 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201228/47d8ca13/attachment.bin>


More information about the llvm-commits mailing list