================
@@ -2784,6 +2786,59 @@ void LoweringPreparePass::lowerStdOp(cir::StdOpInterface 
typedOp) {
   op->erase();
 }
 
+/// If `cond` is the result of a chain of cir.not ops, sets it to the input of
+/// the innermost cir.not and erases the cir.not ops left without uses.  An
+/// odd number of cir.not ops inverts the condition, so `trueRegion` and
+/// `falseRegion` are swapped.  If one region is empty, the other is empty
+/// after a swap, and the caller restores any region its op requires.  Returns
+/// true if the regions were swapped.
+static bool stripNotsFromCondition(mlir::OpOperand &cond,
+                                   mlir::Region &trueRegion,
+                                   mlir::Region &falseRegion) {
+  llvm::SmallVector<cir::NotOp> notOps;
+  mlir::Value value = cond.get();
+  while (auto notOp = value.getDefiningOp<cir::NotOp>()) {
+    notOps.push_back(notOp);
+    value = notOp.getInput();
+  }
+  if (notOps.empty())
+    return false;
+
+  cond.set(value);
+  bool swapped = notOps.size() % 2 == 1;
+  if (swapped) {
+    mlir::Region trueBody;
----------------
adams381 wrote:

Stripping the nots no longer touches the regions.  The callers swap them when 
the condition is inverted.


https://github.com/llvm/llvm-project/pull/233918
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to