[PATCH] D4276: Added llvm.is.constant intrinsic

Bharathi Seshadri via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 18 17:03:44 PDT 2018


Bharathi added a comment.

This feature would be very useful to us and testing this patch against our code base gave us an interesting case where llvm.is.constant (used in a conditional) is lowered to false in CodeGenPrepare and the dead branch that arises out of this lowering does not get eliminated. The code that gets generated after CodeGenPrepare pass has "br i1 false .." with both true and false conditions preserved and this propagates further and remains the same in the final assembly code.

In CodeGenPrepare::runOnFunction, ConstantFoldTerminator (which handles the br i1 false condition) is called only once and if after the transformation of ConstantFoldTerminator() and DeleteDeadBlock(), if we end up with  code like "br i1 false", there is no further opportunity to clean them up.  So calling the code under ' if (!DisableBranchOpts)' in a loop that is conditioned on MadeChange (similar to other places), fixes the issue.  Is this reasonable ?

I wrote a patch to test this and I have one regression with llvm/test/CodeGen/AMDGPU/nested-loop-conditions.ll. I'm having some difficulty to determine if this warrants rewriting the test case to adjust with the new results or if this is a real issue.

Any pointers would be greatly appreciated. My simple fix (without any indentation changes) is:

  --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
  +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
  @@ -316,7 +316,9 @@ bool CodeGenPrepare::runOnFunction(Function &F) {
   
     SunkAddrs.clear();
   
  +  MadeChange = true;
     if (!DisableBranchOpts) {
  +  while (MadeChange) {
       MadeChange = false;
       SmallPtrSet<BasicBlock*, 8> WorkList;
       for (BasicBlock &BB : F) {
  @@ -352,6 +354,7 @@ bool CodeGenPrepare::runOnFunction(Function &F) {
   
       EverMadeChange |= MadeChange;
     }
  + }
   
     if (!DisableGCOpts) {
       SmallVector<Instruction *, 2> Statepoints;

Thanks.


https://reviews.llvm.org/D4276





More information about the llvm-commits mailing list