[llvm] [InstSimplify] Fix Inconsistent PHI Simplification (PR #113037)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 19 06:29:42 PDT 2024
================
@@ -0,0 +1,117 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
+
+define <2 x i1> @test_vec_undef_poison(i1 %c) {
+; CHECK-LABEL: define <2 x i1> @test_vec_undef_poison(
+; CHECK-SAME: i1 [[C:%.*]]) {
+; CHECK-NEXT: br i1 [[C]], label %[[T:.*]], label %[[F:.*]]
+; CHECK: [[T]]:
+; CHECK-NEXT: br label %[[M:.*]]
+; CHECK: [[F]]:
+; CHECK-NEXT: br label %[[M]]
+; CHECK: [[M]]:
+; CHECK-NEXT: ret <2 x i1> <i1 undef, i1 false>
+;
+ br i1 %c, label %t, label %f
+t:
+ br label %m
+f:
+ br label %m
+m:
+ %res = phi <2 x i1> [ <i1 undef, i1 poison>, %t ], [ <i1 poison, i1 false>, %f ]
+ ret <2 x i1> %res
+}
+
+define <2 x i1> @test_vec_poison_undef(i1 %c) {
+; CHECK-LABEL: define <2 x i1> @test_vec_poison_undef(
+; CHECK-SAME: i1 [[C:%.*]]) {
+; CHECK-NEXT: br i1 [[C]], label %[[T:.*]], label %[[F:.*]]
+; CHECK: [[T]]:
+; CHECK-NEXT: br label %[[M:.*]]
+; CHECK: [[F]]:
+; CHECK-NEXT: br label %[[M]]
+; CHECK: [[M]]:
+; CHECK-NEXT: ret <2 x i1> <i1 false, i1 undef>
+;
+ br i1 %c, label %t, label %f
+t:
+ br label %m
+f:
+ br label %m
+m:
+ %res = phi <2 x i1> [ <i1 false, i1 poison>, %t ], [ <i1 poison, i1 undef>, %f ]
+ ret <2 x i1> %res
+}
+
+define <2 x i1> @test_vec_poison_undef_defined(i1 %c1, i1 %c2) {
+; CHECK-LABEL: define <2 x i1> @test_vec_poison_undef_defined(
+; CHECK-SAME: i1 [[C1:%.*]], i1 [[C2:%.*]]) {
+; CHECK-NEXT: br i1 [[C1]], label %[[T:.*]], label %[[F:.*]]
+; CHECK: [[T]]:
+; CHECK-NEXT: br i1 [[C2]], label %[[TT:.*]], label %[[TF:.*]]
+; CHECK: [[TT]]:
+; CHECK-NEXT: br label %[[M:.*]]
+; CHECK: [[TF]]:
+; CHECK-NEXT: br label %[[M]]
+; CHECK: [[F]]:
+; CHECK-NEXT: br label %[[M]]
+; CHECK: [[M]]:
+; CHECK-NEXT: ret <2 x i1> <i1 false, i1 true>
+;
+ br i1 %c1, label %t, label %f
+t:
+ br i1 %c2, label %tt, label %tf
+tt:
+ br label %m
+tf:
+ br label %m
+f:
+ br label %m
+m:
+ %res = phi <2 x i1> [ <i1 false, i1 poison>, %tt ], [ <i1 undef, i1 undef>, %tf ], [ <i1 poison, i1 true>, %f ]
+ ret <2 x i1> %res
+}
+
+define <2 x i8> @test_vec_same_constants(i1 %c) {
+; CHECK-LABEL: define <2 x i8> @test_vec_same_constants(
+; CHECK-SAME: i1 [[C:%.*]]) {
+; CHECK-NEXT: br i1 [[C]], label %[[T:.*]], label %[[F:.*]]
+; CHECK: [[T]]:
+; CHECK-NEXT: br label %[[M:.*]]
+; CHECK: [[F]]:
+; CHECK-NEXT: br label %[[M]]
+; CHECK: [[M]]:
+; CHECK-NEXT: ret <2 x i8> <i8 4, i8 2>
+;
+ br i1 %c, label %t, label %f
+t:
+ br label %m
+f:
+ br label %m
+m:
+ %res = phi <2 x i8> [ <i8 4, i8 2>, %t ], [ <i8 4, i8 2>, %f ]
+ ret <2 x i8> %res
+}
+
+; Negative test
+define <2 x i8> @test_vec_different_constants(i1 %c) {
+; CHECK-LABEL: define <2 x i8> @test_vec_different_constants(
+; CHECK-SAME: i1 [[C:%.*]]) {
+; CHECK-NEXT: br i1 [[C]], label %[[T:.*]], label %[[F:.*]]
+; CHECK: [[T]]:
+; CHECK-NEXT: br label %[[M:.*]]
+; CHECK: [[F]]:
+; CHECK-NEXT: br label %[[M]]
+; CHECK: [[M]]:
+; CHECK-NEXT: [[RES:%.*]] = phi <2 x i8> [ <i8 4, i8 2>, %[[T]] ], [ <i8 2, i8 4>, %[[F]] ]
+; CHECK-NEXT: ret <2 x i8> [[RES]]
+;
+ br i1 %c, label %t, label %f
+t:
+ br label %m
+f:
+ br label %m
+m:
+ %res = phi <2 x i8> [ <i8 4, i8 2>, %t ], [ <i8 2, i8 4>, %f ]
+ ret <2 x i8> %res
+}
----------------
arsenm wrote:
Test some struct and array cases
https://github.com/llvm/llvm-project/pull/113037
More information about the llvm-commits
mailing list