Given a while loop whose condition is given by a cmp, don't recomputed the comparison (or its inverse) in the after region, instead use a constant since the original condition must be true if we branched to the after region.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
mlir/lib/Dialect/SCF/SCF.cpp | ||
---|---|---|
2468 | Shouldn't this be handled in CSE: the expression in the do block should be hoisted in the condition block here? |
mlir/lib/Dialect/SCF/SCF.cpp | ||
---|---|---|
2468 | Will CSE actually hoist from the do block into the while? Running this test on CSE, implies no (though that would certainly be desirable). Regardless, this also handles the case where the condition is the negation. |
mlir/lib/Dialect/SCF/SCF.cpp | ||
---|---|---|
2468 | I think part of the reason CSE can't perform this hoisting is because the argument's aren't completely the same (e.g. the later comparison uses the block arguments, which are only defined at the start of the after region). |
mlir/lib/Dialect/SCF/SCF.cpp | ||
---|---|---|
2496–2497 | Do you have coverage for when this gets hit twice? |
mlir/lib/Dialect/SCF/SCF.cpp | ||
---|---|---|
2468 |
Right, I didn't mean that CSE already implements it, just that this is where it belongs :) | |
2483 | ||
2496–2497 | I suspect we'll be missing an make_early_inc_range for the for (auto &u : std::get<1>(tup).getUses()) { |
mlir/lib/Dialect/SCF/SCF.cpp | ||
---|---|---|
2494–2496 | No, as the owner is the comparison cmp2, which has its rhs equal to the comparison in the before block's rhs (and thus cannot be a blockArg to the after region). |
mlir/lib/Dialect/SCF/SCF.cpp | ||
---|---|---|
2494–2496 | I don't think so because of the condition line 2489? (if (cmp2.getRhs() != cmp.getRhs())) By the way this make the pattern only catch one side isn't it? If I just reverse the operands we'll bail out: %condition = arith.cmpi ne, %arg0, %val : i32 scf.condition(%condition) %val : i32 } do { ^bb0(%val2: i32): %condition2 = arith.cmpi ne, %arg0, %val2 : i32 %negcondition2 = arith.cmpi eq, %arg0, %val2 : i32 "test.use"(%condition2, %negcondition2, %val2) : (i1, i1, i32) -> () Also it seems like it won't handle cases where both operands come from the condition block. |
Shouldn't this be handled in CSE: the expression in the do block should be hoisted in the condition block here?