Skip to content

[SimplifyCFG] transform undef to unreachable #85510

Open
@dianqk

Description

@dianqk

I tried the following code:

define noundef i32 @src(i32 noundef %arg) {
bb:
  switch i32 %arg, label %bb5 [
    i32 1, label %bb1
    i32 2, label %bb2
    i32 3, label %bb3
    i32 4, label %bb4
  ]

bb1:                                              ; preds = %bb
  br label %bb5

bb2:                                              ; preds = %bb
  br label %bb5

bb3:                                              ; preds = %bb
  br label %bb5

bb4:                                              ; preds = %bb
  br label %bb5

bb5:                                              ; preds = %bb4, %bb3, %bb2, %bb1, %bb
  %i = phi i32 [ undef, %bb ], [ 4, %bb4 ], [ 3, %bb3 ], [ 2, %bb2 ], [ 1, %bb1 ]
  ret i32 %i
}

define noundef i32 @tgt(i32 noundef %arg) {
bb:
  ret i32 %arg
}

src can be transformed into a return statement because bb through bb5 is undefined behavior.
Perhaps we will be blocked by #78578 if we fix this issue.

alive2: https://alive2.llvm.org/ce/z/Sz6r-e
godbolt: https://llvm.godbolt.org/z/sjrT7Ms6e

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