Skip to content

[SimplifyCFG] ForwardSwitchConditionToPHI missed some cases #95919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dianqk opened this issue Jun 18, 2024 · 0 comments · Fixed by #95932
Closed

[SimplifyCFG] ForwardSwitchConditionToPHI missed some cases #95919

dianqk opened this issue Jun 18, 2024 · 0 comments · Fixed by #95932

Comments

@dianqk
Copy link
Member

dianqk commented Jun 18, 2024

I tried this IR:

define { i64, i64 } @src(i64 noundef %arg, i64 noundef %arg1) local_unnamed_addr #0 {
bb:
  switch i64 %arg1, label %bb7 [
    i64 0, label %bb3
    i64 1, label %bb2
  ]

bb2:                                              ; preds = %bb
  br label %bb3

bb7:                                              ; preds = %bb
  %i8 = udiv i64 %arg, %arg1
  %i13 = shl nuw i64 %i8, 1
  br label %bb3

bb3:                                              ; preds = %bb7, %bb2, %bb
  %i = phi i64 [ %i13, %bb7 ], [ %arg, %bb2 ], [ undef, %bb ]
  %i4 = phi i64 [ 1, %bb7 ], [ 1, %bb2 ], [ %arg1, %bb ]
  %i5 = insertvalue { i64, i64 } poison, i64 %i4, 0
  %i6 = insertvalue { i64, i64 } %i5, i64 %i, 1
  ret { i64, i64 } %i6
}

We can replace [ 1, %bb2 ] with [ %arg1, %bb2 ]. Then the final IR will become to:

define { i64, i64 } @tgt(i64 noundef %arg, i64 noundef %arg1) {
bb:
  %switch = icmp ult i64 %arg1, 2
  br i1 %switch, label %bb3, label %bb7

bb7:                                              ; preds = %bb
  %i8 = udiv i64 %arg, %arg1
  %i13 = shl nuw i64 %i8, 1
  br label %bb3

bb3:                                              ; preds = %bb, %bb7
  %i = phi i64 [ %i13, %bb7 ], [ %arg, %bb ]
  %i4 = phi i64 [ 1, %bb7 ], [ %arg1, %bb ]
  %i5 = insertvalue { i64, i64 } poison, i64 %i4, 0
  %i6 = insertvalue { i64, i64 } %i5, i64 %i, 1
  ret { i64, i64 } %i6
}

Alive2: https://alive2.llvm.org/ce/z/HvwxHB.
From: rust-lang/rust#126585.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants