Skip to content

Missed optimization: conditional store of zext(i1) not folded to constant zero when i1 is known false #138636

Open
@GINN-Imp

Description

@GINN-Imp

The following reduced IR is derived from https://github.com/c3lang/c3c/blob/125436d23ef9b7f69837a00ffec168c52839a1dc/src/compiler/bigint.c#L777

Godbolt: https://godbolt.org/z/jTWv4o5n8
Missed optimization: store i8 %4, ptr %2, align 1 --> store i8 0, ptr %2, align 1
alive2 proof: https://alive2.llvm.org/ce/z/ZQ5aad

define void @src(ptr writeonly captures(none) initializes((0, 1)) %0, i1 %1, ptr writeonly captures(none) %2) local_unnamed_addr #0 {
  %4 = zext i1 %1 to i8
  store i8 %4, ptr %0, align 1
  br i1 %1, label %6, label %5

5:                                                ; preds = %3
  store i8 %4, ptr %2, align 1
  br label %6

6:                                                ; preds = %5, %3
  ret void
}

opt-trunk -O3 generates:

define void @src(ptr writeonly captures(none) initializes((0, 1)) %0, i1 %1, ptr writeonly captures(none) %2) local_unnamed_addr #0 {
  %4 = zext i1 %1 to i8
  store i8 %4, ptr %0, align 1
  br i1 %1, label %6, label %5

5:                                                ; preds = %3
  store i8 %4, ptr %2, align 1
  br label %6

6:                                                ; preds = %5, %3
  ret void
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions