================ @@ -1658,6 +1828,170 @@ mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr( cgf.cgm.UInt64Ty, e->EvaluateKnownConstInt(cgf.getContext()))); } +/// Return true if the specified expression is cheap enough and side-effect-free +/// enough to evaluate unconditionally instead of conditionally. This is used +/// to convert control flow into selects in some cases. +/// TODO(cir): can be shared with LLVM codegen. +static bool isCheapEnoughToEvaluateUnconditionally(const Expr *e, + CIRGenFunction &cgf) { + // Anything that is an integer or floating point constant is fine. + return e->IgnoreParens()->isEvaluatable(cgf.getContext()); ---------------- mmha wrote:
Good catch! I modified your example a bit because of a comment in `Expr.h` on `Expr::EvalStatus::HasUndefinedBehavior`: https://godbolt.org/z/Kvn3M9hr7 > For example, 1.0 / 0.0 can be folded to Inf, but has undefined behavior. Looks like Info.noteUndefinedBehavior() doesn't get called for FP division by zero in `handleFloatFloatBinOp()`. Easy enough fix, I'll create a separate PR for this :) If we want to be strict about this wouldn't this exclude almost any speculative FP expression evaluation as the FP environment can be set at runtime to make this observable? E. g. trapping on inexact results happens pretty much all the time. https://github.com/llvm/llvm-project/pull/138156 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits