[PATCH] D17518: [ifcnv] Don't duplicate blocks that contain convergent instructions.
Justin Lebar via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 14 18:44:21 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266404: [ifcnv] Don't duplicate blocks that contain convergent instructions. (authored by jlebar).
Changed prior to commit:
http://reviews.llvm.org/D17518?vs=53776&id=53828#toc
Repository:
rL LLVM
http://reviews.llvm.org/D17518
Files:
llvm/trunk/lib/CodeGen/IfConversion.cpp
Index: llvm/trunk/lib/CodeGen/IfConversion.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/IfConversion.cpp
+++ llvm/trunk/lib/CodeGen/IfConversion.cpp
@@ -678,7 +678,37 @@
if (MI.isDebugValue())
continue;
- if (MI.isNotDuplicable())
+ // It's unsafe to duplicate convergent instructions in this context, so set
+ // BBI.CannotBeCopied to true if MI is convergent. To see why, consider the
+ // following CFG, which is subject to our "simple" transformation.
+ //
+ // BB0 // if (c1) goto BB1; else goto BB2;
+ // / \
+ // BB1 |
+ // | BB2 // if (c2) goto TBB; else goto FBB;
+ // | / |
+ // | / |
+ // TBB |
+ // | |
+ // | FBB
+ // |
+ // exit
+ //
+ // Suppose we want to move TBB's contents up into BB1 and BB2 (in BB1 they'd
+ // be unconditional, and in BB2, they'd be predicated upon c2), and suppose
+ // TBB contains a convergent instruction. This is safe iff doing so does
+ // not add a control-flow dependency to the convergent instruction -- i.e.,
+ // it's safe iff the set of control flows that leads us to the convergent
+ // instruction does not get smaller after the transformation.
+ //
+ // Originally we executed TBB if c1 || c2. After the transformation, there
+ // are two copies of TBB's instructions. We get to the first if c1, and we
+ // get to the second if !c1 && c2.
+ //
+ // There are clearly fewer ways to satisfy the condition "c1" than
+ // "c1 || c2". Since we've shrunk the set of control flows which lead to
+ // our convergent instruction, the transformation is unsafe.
+ if (MI.isNotDuplicable() || MI.isConvergent())
BBI.CannotBeCopied = true;
bool isPredicated = TII->isPredicated(MI);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17518.53828.patch
Type: text/x-patch
Size: 1856 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160415/84a39c0f/attachment.bin>
More information about the llvm-commits
mailing list