adams381 wrote:
Classic decides how an `if` or `?:` condition becomes branches in
EmitBranchOnBoolExpr. `!x` swaps the targets, and `&&` and `||` become branch
chains straight to the targets with no phi. It does this at every optimization
level. The CIR counterpart is emitOpOnBoolExpr, and its comment says the
reversal should happen in CIR before LLVM lowering rather than in CIRGen, so
that CIR-based diagnostics stay accurate.
That leaves the CIR passes. Canonicalize and simplify run on structured CIR,
where the only way to drop the `cir.not` from `if (!x) f();` is `cir.if %x {}
else { ... }`, and `if (a || b)` has to materialize a bool. FlattenCFG is the
first place the condition becomes branches, which is the step
EmitBranchOnBoolExpr models.
So, I think it belongs in FlattenCFG, but should probably be put into a helper
that emits a condition as branches the way classic does. The helper can be
used for `cir.if` and `cir.ternary` but not for loops, since classic branches
on the value there.
I've written this PR to cover `!`. I can add the branch for `&&` and `||`
straight to the targets if you want one PR to fully match classic.
https://github.com/llvm/llvm-project/pull/233918
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits