From 7769c1e623391445652066becb3732f47906f788 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pawe=C5=82=20Bylica?= Date: Wed, 19 Jul 2023 13:54:51 +0200 Subject: [PATCH] [InstCombine][NFC] Add tests for preserving metadata Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D155594 --- llvm/test/Transforms/InstCombine/select_meta.ll | 91 ++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/llvm/test/Transforms/InstCombine/select_meta.ll b/llvm/test/Transforms/InstCombine/select_meta.ll index 0255481..91bd28b 100644 --- a/llvm/test/Transforms/InstCombine/select_meta.ll +++ b/llvm/test/Transforms/InstCombine/select_meta.ll @@ -1,5 +1,4 @@ -; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; and enhanced to include metadata checking. +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals ; RUN: opt < %s -passes=instcombine -S | FileCheck %s @@ -64,8 +63,8 @@ define i32 @foo2(i32, i32) local_unnamed_addr #0 { define i64 @test43(i32 %a) nounwind { ; CHECK-LABEL: @test43( -; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.smax.i32(i32 [[A:%.*]], i32 0) -; CHECK-NEXT: [[MAX:%.*]] = zext i32 [[TMP1]] to i64 +; CHECK-NEXT: [[NARROW:%.*]] = call i32 @llvm.smax.i32(i32 [[A:%.*]], i32 0) +; CHECK-NEXT: [[MAX:%.*]] = zext i32 [[NARROW]] to i64 ; CHECK-NEXT: ret i64 [[MAX]] ; %a_ext = sext i32 %a to i64 @@ -316,10 +315,86 @@ define <2 x i32> @not_cond_vec_undef(<2 x i1> %c, <2 x i32> %tv, <2 x i32> %fv) ret <2 x i32> %r } +; TODO: The metadata should be preserved. +define i64 @select_add(i1 %cond, i64 %x, i64 %y) { +; CHECK-LABEL: @select_add( +; CHECK-NEXT: [[OP:%.*]] = select i1 [[COND:%.*]], i64 [[Y:%.*]], i64 0 +; CHECK-NEXT: [[RET:%.*]] = add i64 [[OP]], [[X:%.*]] +; CHECK-NEXT: ret i64 [[RET]] +; + %op = add i64 %x, %y + %ret = select i1 %cond, i64 %op, i64 %x, !prof !1, !unpredictable !3 + ret i64 %ret +} -!1 = !{!"branch_weights", i32 2, i32 10} -!2 = !{!"branch_weights", i32 3, i32 10} +; TODO: The metadata should be preserved. +define <2 x i32> @select_or(<2 x i1> %cond, <2 x i32> %x, <2 x i32> %y) { +; CHECK-LABEL: @select_or( +; CHECK-NEXT: [[OP:%.*]] = select <2 x i1> [[COND:%.*]], <2 x i32> [[Y:%.*]], <2 x i32> zeroinitializer +; CHECK-NEXT: [[RET:%.*]] = or <2 x i32> [[OP]], [[X:%.*]] +; CHECK-NEXT: ret <2 x i32> [[RET]] +; + %op = or <2 x i32> %x, %y + %ret = select <2 x i1> %cond, <2 x i32> %op, <2 x i32> %x, !prof !1, !unpredictable !3 + ret <2 x i32> %ret +} -; CHECK: !0 = !{!"branch_weights", i32 2, i32 10} -; CHECK-NEXT: !1 = !{!"branch_weights", i32 10, i32 2} +; TODO: The metadata should be preserved. +define i17 @select_sub(i1 %cond, i17 %x, i17 %y) { +; CHECK-LABEL: @select_sub( +; CHECK-NEXT: [[OP:%.*]] = select i1 [[COND:%.*]], i17 [[Y:%.*]], i17 0 +; CHECK-NEXT: [[RET:%.*]] = sub i17 [[X:%.*]], [[OP]] +; CHECK-NEXT: ret i17 [[RET]] +; + %op = sub i17 %x, %y + %ret = select i1 %cond, i17 %op, i17 %x, !prof !1, !unpredictable !3 + ret i17 %ret +} +; TODO: The metadata should be preserved. +define i128 @select_ashr(i1 %cond, i128 %x, i128 %y) { +; CHECK-LABEL: @select_ashr( +; CHECK-NEXT: [[OP:%.*]] = select i1 [[COND:%.*]], i128 [[Y:%.*]], i128 0 +; CHECK-NEXT: [[RET:%.*]] = ashr i128 [[X:%.*]], [[OP]] +; CHECK-NEXT: ret i128 [[RET]] +; + %op = ashr i128 %x, %y + %ret = select i1 %cond, i128 %op, i128 %x, !prof !1, !unpredictable !3 + ret i128 %ret +} + +; TODO: The metadata should be preserved. +define double @select_fmul(i1 %cond, double %x, double %y) { +; CHECK-LABEL: @select_fmul( +; CHECK-NEXT: [[OP:%.*]] = select i1 [[COND:%.*]], double [[Y:%.*]], double 1.000000e+00 +; CHECK-NEXT: [[RET:%.*]] = fmul double [[OP]], [[X:%.*]] +; CHECK-NEXT: ret double [[RET]] +; + %op = fmul double %x, %y + %ret = select i1 %cond, double %op, double %x, !prof !1, !unpredictable !3 + ret double %ret +} + +; TODO: The metadata should be preserved. +define <2 x float> @select_fdiv(i1 %cond, <2 x float> %x, <2 x float> %y) { +; CHECK-LABEL: @select_fdiv( +; CHECK-NEXT: [[OP:%.*]] = select i1 [[COND:%.*]], <2 x float> [[Y:%.*]], <2 x float> +; CHECK-NEXT: [[RET:%.*]] = fdiv <2 x float> [[X:%.*]], [[OP]] +; CHECK-NEXT: ret <2 x float> [[RET]] +; + %op = fdiv <2 x float> %x, %y + %ret = select i1 %cond, <2 x float> %op, <2 x float> %x, !prof !1, !unpredictable !3 + ret <2 x float> %ret +} + +!1 = !{!"branch_weights", i32 2, i32 10} +!2 = !{!"branch_weights", i32 3, i32 10} +!3 = !{} + +;. +; CHECK: attributes #[[ATTR0:[0-9]+]] = { nounwind } +; CHECK: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } +;. +; CHECK: [[PROF0]] = !{!"branch_weights", i32 2, i32 10} +; CHECK: [[PROF1]] = !{!"branch_weights", i32 10, i32 2} +;. -- 2.7.4