- out = (ast_expression*)ast_binary_new(ctx, INSTR_DIV_F,
- (ast_expression*)parser_const_float_1(parser),
- exprs[1]);
- if (!out)
+ if (CanConstFold1(exprs[1])) {
+ out = (ast_expression*)parser_const_float(parser, 1.0 / ConstF(1));
+ } else {
+ out = (ast_expression*)ast_binary_new(ctx, INSTR_DIV_F,
+ (ast_expression*)parser_const_float_1(parser),
+ exprs[1]);
+ }
+ if (!out) {
+ compile_error(ctx, "internal error: failed to generate division");