[PATCH] D153660: [ConstraintElim] Track and simplify conditions at use.

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 27 06:15:38 PDT 2023


nikic added a comment.

Can you please also add a test along these lines?

  define i1 @test(i1 %c, i32 %x) {
  entry:
    br i1 %c, label %if, label %join
  
  if: 
    %cmp1 = icmp sgt i32 %x, 1
    %cmp2 = icmp sgt i32 %x, 0
    br i1 %cmp1, label %join, label %exit
  
  join:
    %phi = phi i1 [ %cmp2, %if ], [ false, %entry ]
    ret i1 %phi
  
  exit:
    ret i1 false
  }

Here the fact is known only along the edge, but in neither of the blocks. I don't expect this to actually get folded...



================
Comment at: llvm/lib/Transforms/Scalar/ConstraintElimination.cpp:666
+  if (auto *Phi = dyn_cast<PHINode>(UserI))
+    UserI = Phi->getIncomingBlock(U.getOperandNo())->getTerminator();
+  return UserI;
----------------
No need for getOperandNo, there's an overload for Uses.


================
Comment at: llvm/lib/Transforms/Scalar/ConstraintElimination.cpp:721
+      return Inst;
+    return dyn_cast<Instruction>(*U);
+  }
----------------
The dyn_cast is needed because it may have been replaced by a constant already?


================
Comment at: llvm/lib/Transforms/Scalar/ConstraintElimination.cpp:1285
 
-    LLVM_DEBUG({
-      dbgs() << "Processing ";
-      if (CB.IsCheck)
-        dbgs() << "condition to simplify: " << *CB.Inst;
-      else
-        dbgs() << "fact to add to the system: " << *CB.Inst;
-      dbgs() << "\n";
-    });
+    LLVM_DEBUG(dbgs() << "Processing ";);
 
----------------
Stray semicolon


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153660/new/

https://reviews.llvm.org/D153660



More information about the llvm-commits mailing list