Skip to content

Missed optimization: unconditional ret i1 false not folded in simple control flow with icmp sgt and phi #146263

Open
@GINN-Imp

Description

@GINN-Imp

The following reduced IR is derived from https://github.com/python/cpython/blob/30ba03ea8ed98522b0500d6856b22727c88e818f/Modules/_json.c#L793

Godbolt: https://godbolt.org/z/4P4KfMsaz
alive2 proof: https://alive2.llvm.org/ce/z/FF_D8Z

define noundef i1 @_parse_array_unicode(i64 %0, i1 %1, i64 %2) local_unnamed_addr #0 {
  br i1 %1, label %4, label %5

4:
  %.not.not = icmp sgt i64 %2, %0
  br i1 %.not.not, label %common.ret1, label %5

common.ret1:
  %common.ret1.op = phi i1 [ %6, %5 ], [ false, %4 ]
  ret i1 %common.ret1.op

5:
  %.0 = phi i64 [ %0, %3 ], [ %2, %4 ]
  %6 = icmp sgt i64 %.0, %0
  br label %common.ret1
}

expected:

define noundef i1 @tgt(i64 %0, i1 %1, i64 %2) local_unnamed_addr #0 {
  ret i1 false
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions