[PATCH] D33257: [JumpThreading] Dont RAUW condition if guards in block

Sanjoy Das via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 16 14:58:52 PDT 2017


sanjoy requested changes to this revision.
sanjoy added inline comments.
This revision now requires changes to proceed.


================
Comment at: lib/Transforms/Scalar/JumpThreading.cpp:266
+      Intrinsic::getName(Intrinsic::experimental_guard));
+  if (GuardDecl && !GuardDecl->use_empty()) {
+    // Traversing the uses requires checking for `Cond` being used directly in
----------------
I don't think this is specific to guards.  For instance, if you have:

```
bb:
  cond = icmp ...;
  print(cond);
  exit();
  assume(cond);
  br cond;
```

You can't simplify the `cond` in `print(cond)` to `print(true)`.  I think there are similar issues with `isObjectDereferencedInBlock`.

I'd instead phrase this problem as:

We know that at the end of a basic block, a certain condition, `cond`, is true.  The question from what point onwards did that condition become true.  To do that, I suggest walking backwards from the branch, and stopping when you find an instruction for which `isGuaranteedToTransferExecutionToSuccessor` returns false.  All the instructions you enumerate this way can be `replaceUsesOfWith(cond, true)` 'ed.  This approach will miss some cases though, like in:

```
bb:
  cond = icmp ...;
  print(cond);
  cond' = or cond, something_else
  exit();
  use(cond')
  assume(cond);
  br cond;
```

we won't simplify `cond'`.  If needed, we can come up with a more aggressive substitution scheme to get those cases.



https://reviews.llvm.org/D33257





More information about the llvm-commits mailing list