[llvm] 8bfe46d - [NFC][InstCombine] Add tests with PHI-of-{insert,extract}value with multiple uses
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 26 10:20:53 PDT 2020
Author: Roman Lebedev
Date: 2020-08-26T20:20:41+03:00
New Revision: 8bfe46dce22266e596370eac86b1aae799300e7e
URL: https://github.com/llvm/llvm-project/commit/8bfe46dce22266e596370eac86b1aae799300e7e
DIFF: https://github.com/llvm/llvm-project/commit/8bfe46dce22266e596370eac86b1aae799300e7e.diff
LOG: [NFC][InstCombine] Add tests with PHI-of-{insert,extract}value with multiple uses
It is fine if the operation has multiple uses, as long as they are all
in this very PHI node.
Added:
Modified:
llvm/test/Transforms/InstCombine/phi-of-extractvalues.ll
llvm/test/Transforms/InstCombine/phi-of-insertvalues.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/phi-of-extractvalues.ll b/llvm/test/Transforms/InstCombine/phi-of-extractvalues.ll
index 46cbd123f5fb..11337c7d41e3 100644
--- a/llvm/test/Transforms/InstCombine/phi-of-extractvalues.ll
+++ b/llvm/test/Transforms/InstCombine/phi-of-extractvalues.ll
@@ -312,3 +312,76 @@ end:
%r = phi i32 [ %i0, %left ], [ %i1, %right ]
ret i32 %r
}
+
+; It is fine if there are multiple uses of the PHI's value, as long as they are all in the PHI node itself
+define i32 @test10({ i32, i32 } %agg_left, { i32, i32 } %agg_right, i1 %c0, i1 %c1) {
+; CHECK-LABEL: @test10(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[I0:%.*]] = extractvalue { i32, i32 } [[AGG_LEFT:%.*]], 0
+; CHECK-NEXT: [[I1:%.*]] = extractvalue { i32, i32 } [[AGG_RIGHT:%.*]], 0
+; CHECK-NEXT: br i1 [[C0:%.*]], label [[END:%.*]], label [[DISPATCH:%.*]]
+; CHECK: dispatch:
+; CHECK-NEXT: br i1 [[C1:%.*]], label [[LEFT:%.*]], label [[RIGHT:%.*]]
+; CHECK: left:
+; CHECK-NEXT: br label [[END]]
+; CHECK: right:
+; CHECK-NEXT: br label [[END]]
+; CHECK: end:
+; CHECK-NEXT: [[R:%.*]] = phi i32 [ [[I0]], [[ENTRY:%.*]] ], [ [[I0]], [[LEFT]] ], [ [[I1]], [[RIGHT]] ]
+; CHECK-NEXT: ret i32 [[R]]
+;
+entry:
+ %i0 = extractvalue { i32, i32 } %agg_left, 0
+ %i1 = extractvalue { i32, i32 } %agg_right, 0
+ br i1 %c0, label %end, label %dispatch
+
+dispatch:
+ br i1 %c1, label %left, label %right
+
+left:
+ br label %end
+
+right:
+ br label %end
+
+end:
+ %r = phi i32 [ %i0, %entry ], [ %i0, %left ], [ %i1, %right ]
+ ret i32 %r
+}
+; Which isn't the case here, there is a legitimate external use.
+define i32 @test11({ i32, i32 } %agg_left, { i32, i32 } %agg_right, i1 %c0, i1 %c1) {
+; CHECK-LABEL: @test11(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[I0:%.*]] = extractvalue { i32, i32 } [[AGG_LEFT:%.*]], 0
+; CHECK-NEXT: [[I1:%.*]] = extractvalue { i32, i32 } [[AGG_RIGHT:%.*]], 0
+; CHECK-NEXT: call void @usei32(i32 [[I0]])
+; CHECK-NEXT: br i1 [[C0:%.*]], label [[END:%.*]], label [[DISPATCH:%.*]]
+; CHECK: dispatch:
+; CHECK-NEXT: br i1 [[C1:%.*]], label [[LEFT:%.*]], label [[RIGHT:%.*]]
+; CHECK: left:
+; CHECK-NEXT: br label [[END]]
+; CHECK: right:
+; CHECK-NEXT: br label [[END]]
+; CHECK: end:
+; CHECK-NEXT: [[R:%.*]] = phi i32 [ [[I0]], [[ENTRY:%.*]] ], [ [[I0]], [[LEFT]] ], [ [[I1]], [[RIGHT]] ]
+; CHECK-NEXT: ret i32 [[R]]
+;
+entry:
+ %i0 = extractvalue { i32, i32 } %agg_left, 0
+ %i1 = extractvalue { i32, i32 } %agg_right, 0
+ call void @usei32(i32 %i0)
+ br i1 %c0, label %end, label %dispatch
+
+dispatch:
+ br i1 %c1, label %left, label %right
+
+left:
+ br label %end
+
+right:
+ br label %end
+
+end:
+ %r = phi i32 [ %i0, %entry ], [ %i0, %left ], [ %i1, %right ]
+ ret i32 %r
+}
diff --git a/llvm/test/Transforms/InstCombine/phi-of-insertvalues.ll b/llvm/test/Transforms/InstCombine/phi-of-insertvalues.ll
index 00e81ad06f73..51bf8e21c1c8 100644
--- a/llvm/test/Transforms/InstCombine/phi-of-insertvalues.ll
+++ b/llvm/test/Transforms/InstCombine/phi-of-insertvalues.ll
@@ -283,3 +283,76 @@ end:
%r = phi {{ i32, i32 }, { i32, i32 }} [ %i0, %left ], [ %i1, %right ]
ret {{ i32, i32 }, { i32, i32 }} %r
}
+
+; It is fine if there are multiple uses of the PHI's value, as long as they are all in the PHI node itself
+define { i32, i32 } @test9({ i32, i32 } %agg, i32 %val_left, i32 %val_right, i1 %c0, i1 %c1) {
+; CHECK-LABEL: @test9(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[I0:%.*]] = insertvalue { i32, i32 } [[AGG:%.*]], i32 [[VAL_LEFT:%.*]], 0
+; CHECK-NEXT: [[I1:%.*]] = insertvalue { i32, i32 } [[AGG]], i32 [[VAL_RIGHT:%.*]], 0
+; CHECK-NEXT: br i1 [[C0:%.*]], label [[END:%.*]], label [[DISPATCH:%.*]]
+; CHECK: dispatch:
+; CHECK-NEXT: br i1 [[C1:%.*]], label [[LEFT:%.*]], label [[RIGHT:%.*]]
+; CHECK: left:
+; CHECK-NEXT: br label [[END]]
+; CHECK: right:
+; CHECK-NEXT: br label [[END]]
+; CHECK: end:
+; CHECK-NEXT: [[R:%.*]] = phi { i32, i32 } [ [[I0]], [[ENTRY:%.*]] ], [ [[I0]], [[LEFT]] ], [ [[I1]], [[RIGHT]] ]
+; CHECK-NEXT: ret { i32, i32 } [[R]]
+;
+entry:
+ %i0 = insertvalue { i32, i32 } %agg, i32 %val_left, 0
+ %i1 = insertvalue { i32, i32 } %agg, i32 %val_right, 0
+ br i1 %c0, label %end, label %dispatch
+
+dispatch:
+ br i1 %c1, label %left, label %right
+
+left:
+ br label %end
+
+right:
+ br label %end
+
+end:
+ %r = phi { i32, i32 } [ %i0, %entry ], [ %i0, %left ], [ %i1, %right ]
+ ret { i32, i32 } %r
+}
+; Which isn't the case here, there is a legitimate external use.
+define { i32, i32 } @test10({ i32, i32 } %agg, i32 %val_left, i32 %val_right, i1 %c0, i1 %c1) {
+; CHECK-LABEL: @test10(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[I0:%.*]] = insertvalue { i32, i32 } [[AGG:%.*]], i32 [[VAL_LEFT:%.*]], 0
+; CHECK-NEXT: [[I1:%.*]] = insertvalue { i32, i32 } [[AGG]], i32 [[VAL_RIGHT:%.*]], 0
+; CHECK-NEXT: call void @usei32i32agg({ i32, i32 } [[I0]])
+; CHECK-NEXT: br i1 [[C0:%.*]], label [[END:%.*]], label [[DISPATCH:%.*]]
+; CHECK: dispatch:
+; CHECK-NEXT: br i1 [[C1:%.*]], label [[LEFT:%.*]], label [[RIGHT:%.*]]
+; CHECK: left:
+; CHECK-NEXT: br label [[END]]
+; CHECK: right:
+; CHECK-NEXT: br label [[END]]
+; CHECK: end:
+; CHECK-NEXT: [[R:%.*]] = phi { i32, i32 } [ [[I0]], [[ENTRY:%.*]] ], [ [[I0]], [[LEFT]] ], [ [[I1]], [[RIGHT]] ]
+; CHECK-NEXT: ret { i32, i32 } [[R]]
+;
+entry:
+ %i0 = insertvalue { i32, i32 } %agg, i32 %val_left, 0
+ %i1 = insertvalue { i32, i32 } %agg, i32 %val_right, 0
+ call void @usei32i32agg({ i32, i32 } %i0)
+ br i1 %c0, label %end, label %dispatch
+
+dispatch:
+ br i1 %c1, label %left, label %right
+
+left:
+ br label %end
+
+right:
+ br label %end
+
+end:
+ %r = phi { i32, i32 } [ %i0, %entry ], [ %i0, %left ], [ %i1, %right ]
+ ret { i32, i32 } %r
+}
More information about the llvm-commits
mailing list