[llvm] [InstCombine] Canonicalize `extractvalue + select` (PR #84686)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 10 12:32:29 PDT 2024
================
@@ -0,0 +1,60 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define i64 @test_select_agg_constant(i64 %val, i1 %cond) {
+; CHECK-LABEL: define i64 @test_select_agg_constant(
+; CHECK-SAME: i64 [[VAL:%.*]], i1 [[COND:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[RET:%.*]] = zext i1 [[COND]] to i64
+; CHECK-NEXT: ret i64 [[RET]]
+;
+entry:
+ %a = insertvalue { i64, i64 } { i64 1, i64 poison }, i64 %val, 1
+ %b = insertvalue { i64, i64 } { i64 0, i64 poison }, i64 %val, 1
+ %sel = select i1 %cond, { i64, i64 } %a, { i64, i64 } %b
+ %ret = extractvalue { i64, i64 } %sel, 0
+ ret i64 %ret
+}
+
+define void @test_select_agg_multiuse(i1 %cond, i64 %v1, i64 %v2, i64 %v3, i64 %v4) {
+; CHECK-LABEL: define void @test_select_agg_multiuse(
+; CHECK-SAME: i1 [[COND:%.*]], i64 [[V1:%.*]], i64 [[V2:%.*]], i64 [[V3:%.*]], i64 [[V4:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[X:%.*]] = select i1 [[COND]], i64 [[V1]], i64 [[V3]]
+; CHECK-NEXT: call void @use(i64 [[X]])
+; CHECK-NEXT: [[Y:%.*]] = select i1 [[COND]], i64 [[V2]], i64 [[V4]]
+; CHECK-NEXT: call void @use(i64 [[Y]])
+; CHECK-NEXT: ret void
+;
+entry:
+ %a0 = insertvalue { i64, i64 } poison, i64 %v1, 0
+ %a1 = insertvalue { i64, i64 } %a0, i64 %v2, 1
+ %b0 = insertvalue { i64, i64 } poison, i64 %v3, 0
+ %b1 = insertvalue { i64, i64 } %b0, i64 %v4, 1
+ %sel = select i1 %cond, { i64, i64 } %a1, { i64, i64 } %b1
+ %x = extractvalue { i64, i64 } %sel, 0
+ call void @use(i64 %x)
+ %y = extractvalue { i64, i64 } %sel, 1
+ call void @use(i64 %y)
+ ret void
+}
+
+define i64 @test_select_agg_simplified(i1 %cond, i64 %v1, i64 %v2, i64 %v3, i64 %v4) {
+; CHECK-LABEL: define i64 @test_select_agg_simplified(
+; CHECK-SAME: i1 [[COND:%.*]], i64 [[V1:%.*]], i64 [[V2:%.*]], i64 [[V3:%.*]], i64 [[V4:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[RET:%.*]] = select i1 [[COND]], i64 [[V2]], i64 0
+; CHECK-NEXT: ret i64 [[RET]]
+;
+entry:
+ %a0 = insertvalue { i64, i64 } poison, i64 %v1, 0
+ %a1 = insertvalue { i64, i64 } %a0, i64 %v2, 1
+ %b0 = insertvalue { i64, i64 } poison, i64 %v3, 0
+ %b1 = insertvalue { i64, i64 } %b0, i64 %v4, 1
+ %sel = select i1 %cond, { i64, i64 } %a1, { i64, i64 } %b1
+ %y = extractvalue { i64, i64 } %sel, 1
+ %ret = select i1 %cond, i64 %y, i64 0
+ ret i64 %ret
+}
----------------
goldsteinn wrote:
Still think the tests would be good, even if its still worth canonicalizing in that case.
https://github.com/llvm/llvm-project/pull/84686
More information about the llvm-commits
mailing list