[PATCH] D88217: [GVN] Make propagateEquality look into the operand of freeze

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 04:32:06 PDT 2020


aqjune created this revision.
aqjune added reviewers: fhahn, spatel, nikic, lebedev.ri, efriedma.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
aqjune requested review of this revision.

Given a program

   x.fr = freeze x
   c = icmp eq x.fr, y
   br c, A, B
  A:
   use(x) // here

We can replace x with y, and this is useful for reducing # of uses of freeze.

This can be proved by case analysis.
If y is undef or poison, c is also undef or poison, so `br c` raises UB.
If y is a well-defined value, x.fr and y are equal, so x (which is more undefined than x) can be replaced with y.

Demonstration: https://alive2.llvm.org/ce/z/UWX2fL , https://alive2.llvm.org/ce/z/vxcMLS , https://alive2.llvm.org/ce/z/_mcXgJ

If the branch condition itself was frozen (`br freeze (icmp eq x, y)`), this optimization isn't valid (https://alive2.llvm.org/ce/z/X5eetc ).
If either x or y is constant, converting it into `br (icmp eq (freeze x), y)` will make the optimization above fire again.
InstCombine might be a good candidate for doing this preprocessing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88217

Files:
  llvm/lib/Transforms/Scalar/GVN.cpp
  llvm/test/Transforms/GVN/freeze.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88217.294015.patch
Type: text/x-patch
Size: 4663 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200924/24a3c061/attachment.bin>


More information about the llvm-commits mailing list