From c2a118d36cf976f18ff44a871e7a97185b06a115 Mon Sep 17 00:00:00 2001 From: Benjamin Maxwell Date: Thu, 10 Jul 2025 09:57:09 +0000 Subject: [PATCH 1/3] [AArch64][SME] Instcombine `llvm.aarch64.sme.in.streaming.mode()` This can fold away in non-streaming-compatible functions. --- .../AArch64/AArch64TargetTransformInfo.cpp | 12 ++++++ .../AArch64/aarch64-sme-in-streaming-mode.ll | 38 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 llvm/test/Transforms/InstCombine/AArch64/aarch64-sme-in-streaming-mode.ll diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp index adc905384bf53..9e64e33818781 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -2723,6 +2723,16 @@ static std::optional instCombineSVEUxt(InstCombiner &IC, return std::nullopt; } +static std::optional +instCombineInStreamingMode(InstCombiner &IC, IntrinsicInst &II) { + SMEAttrs FnSMEAttrs(*II.getFunction()); + if (FnSMEAttrs.hasStreamingCompatibleInterface()) + return std::nullopt; + bool IsStreaming = FnSMEAttrs.hasStreamingInterfaceOrBody(); + return IC.replaceInstUsesWith( + II, ConstantInt::getBool(II.getType(), IsStreaming)); +} + std::optional AArch64TTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const { @@ -2828,6 +2838,8 @@ AArch64TTIImpl::instCombineIntrinsic(InstCombiner &IC, return instCombineSVEUxt(IC, II, 16); case Intrinsic::aarch64_sve_uxtw: return instCombineSVEUxt(IC, II, 32); + case Intrinsic::aarch64_sme_in_streaming_mode: + return instCombineInStreamingMode(IC, II); } return std::nullopt; diff --git a/llvm/test/Transforms/InstCombine/AArch64/aarch64-sme-in-streaming-mode.ll b/llvm/test/Transforms/InstCombine/AArch64/aarch64-sme-in-streaming-mode.ll new file mode 100644 index 0000000000000..c46f5c48429d3 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/AArch64/aarch64-sme-in-streaming-mode.ll @@ -0,0 +1,38 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 +; RUN: opt -passes=instcombine -mtriple aarch64 -mattr=+sme -S -o - < %s | FileCheck %s + +define i1 @test_in_streaming_mode_streaming_compatible() "aarch64_pstate_sm_compatible" { +; CHECK-LABEL: define i1 @test_in_streaming_mode_streaming_compatible( +; CHECK-SAME: ) #[[ATTR0:[0-9]+]] { +; CHECK-NEXT: [[SM:%.*]] = tail call i1 @llvm.aarch64.sme.in.streaming.mode() +; CHECK-NEXT: ret i1 [[SM]] +; + %sm = tail call i1 @llvm.aarch64.sme.in.streaming.mode() + ret i1 %sm +} + +define i1 @test_in_streaming_mode_streaming() "aarch64_pstate_sm_enabled" { +; CHECK-LABEL: define i1 @test_in_streaming_mode_streaming( +; CHECK-SAME: ) #[[ATTR1:[0-9]+]] { +; CHECK-NEXT: ret i1 true +; + %sm = tail call i1 @llvm.aarch64.sme.in.streaming.mode() + ret i1 %sm +} +define i1 @test_in_streaming_mode_streaming_body() "aarch64_pstate_sm_body" { +; CHECK-LABEL: define i1 @test_in_streaming_mode_streaming_body( +; CHECK-SAME: ) #[[ATTR2:[0-9]+]] { +; CHECK-NEXT: ret i1 true +; + %sm = tail call i1 @llvm.aarch64.sme.in.streaming.mode() + ret i1 %sm +} + +define i1 @test_in_streaming_mode_non_streaming() { +; CHECK-LABEL: define i1 @test_in_streaming_mode_non_streaming( +; CHECK-SAME: ) #[[ATTR3:[0-9]+]] { +; CHECK-NEXT: ret i1 false +; + %sm = tail call i1 @llvm.aarch64.sme.in.streaming.mode() + ret i1 %sm +} From 9111616295c7cb61be1e1c0da8476d20cce54f90 Mon Sep 17 00:00:00 2001 From: Benjamin Maxwell Date: Sat, 12 Jul 2025 08:22:29 +0100 Subject: [PATCH 2/3] Apply suggestions from code review --- llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp | 8 ++++---- .../AArch64/aarch64-sme-in-streaming-mode.ll | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp index 9e64e33818781..a40827acaa837 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -2726,11 +2726,11 @@ static std::optional instCombineSVEUxt(InstCombiner &IC, static std::optional instCombineInStreamingMode(InstCombiner &IC, IntrinsicInst &II) { SMEAttrs FnSMEAttrs(*II.getFunction()); - if (FnSMEAttrs.hasStreamingCompatibleInterface()) - return std::nullopt; bool IsStreaming = FnSMEAttrs.hasStreamingInterfaceOrBody(); - return IC.replaceInstUsesWith( - II, ConstantInt::getBool(II.getType(), IsStreaming)); + if (IsStreaming || !FnSMEAttrs.hasStreamingCompatibleInterface()) + return IC.replaceInstUsesWith( + II, ConstantInt::getBool(II.getType(), IsStreaming)); + return std::nullopt; } std::optional diff --git a/llvm/test/Transforms/InstCombine/AArch64/aarch64-sme-in-streaming-mode.ll b/llvm/test/Transforms/InstCombine/AArch64/aarch64-sme-in-streaming-mode.ll index c46f5c48429d3..6de81568a2365 100644 --- a/llvm/test/Transforms/InstCombine/AArch64/aarch64-sme-in-streaming-mode.ll +++ b/llvm/test/Transforms/InstCombine/AArch64/aarch64-sme-in-streaming-mode.ll @@ -19,6 +19,16 @@ define i1 @test_in_streaming_mode_streaming() "aarch64_pstate_sm_enabled" { %sm = tail call i1 @llvm.aarch64.sme.in.streaming.mode() ret i1 %sm } + +define i1 @test_in_streaming_mode_streaming_compatible_streaming_body() "aarch64_pstate_sm_compatible" "aarch64_pstate_sm_body" { +; CHECK-LABEL: define i1 @test_in_streaming_mode_streaming_compatible_streaming_body( +; CHECK-SAME: ) #[[ATTR1:[0-9]+]] { +; CHECK-NEXT: ret i1 true +; + %sm = tail call i1 @llvm.aarch64.sme.in.streaming.mode() + ret i1 %sm +} + define i1 @test_in_streaming_mode_streaming_body() "aarch64_pstate_sm_body" { ; CHECK-LABEL: define i1 @test_in_streaming_mode_streaming_body( ; CHECK-SAME: ) #[[ATTR2:[0-9]+]] { From 79edddf526b5a410eb3ee3aff7fffc448a5b8668 Mon Sep 17 00:00:00 2001 From: Benjamin Maxwell Date: Sat, 12 Jul 2025 08:26:23 +0100 Subject: [PATCH 3/3] Update llvm/test/Transforms/InstCombine/AArch64/aarch64-sme-in-streaming-mode.ll --- .../InstCombine/AArch64/aarch64-sme-in-streaming-mode.ll | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/test/Transforms/InstCombine/AArch64/aarch64-sme-in-streaming-mode.ll b/llvm/test/Transforms/InstCombine/AArch64/aarch64-sme-in-streaming-mode.ll index 6de81568a2365..e8170ba3106a6 100644 --- a/llvm/test/Transforms/InstCombine/AArch64/aarch64-sme-in-streaming-mode.ll +++ b/llvm/test/Transforms/InstCombine/AArch64/aarch64-sme-in-streaming-mode.ll @@ -22,7 +22,7 @@ define i1 @test_in_streaming_mode_streaming() "aarch64_pstate_sm_enabled" { define i1 @test_in_streaming_mode_streaming_compatible_streaming_body() "aarch64_pstate_sm_compatible" "aarch64_pstate_sm_body" { ; CHECK-LABEL: define i1 @test_in_streaming_mode_streaming_compatible_streaming_body( -; CHECK-SAME: ) #[[ATTR1:[0-9]+]] { +; CHECK-SAME: ) #[[ATTR2:[0-9]+]] { ; CHECK-NEXT: ret i1 true ; %sm = tail call i1 @llvm.aarch64.sme.in.streaming.mode() @@ -31,7 +31,7 @@ define i1 @test_in_streaming_mode_streaming_compatible_streaming_body() "aarch64 define i1 @test_in_streaming_mode_streaming_body() "aarch64_pstate_sm_body" { ; CHECK-LABEL: define i1 @test_in_streaming_mode_streaming_body( -; CHECK-SAME: ) #[[ATTR2:[0-9]+]] { +; CHECK-SAME: ) #[[ATTR3:[0-9]+]] { ; CHECK-NEXT: ret i1 true ; %sm = tail call i1 @llvm.aarch64.sme.in.streaming.mode() @@ -40,7 +40,7 @@ define i1 @test_in_streaming_mode_streaming_body() "aarch64_pstate_sm_body" { define i1 @test_in_streaming_mode_non_streaming() { ; CHECK-LABEL: define i1 @test_in_streaming_mode_non_streaming( -; CHECK-SAME: ) #[[ATTR3:[0-9]+]] { +; CHECK-SAME: ) #[[ATTR4:[0-9]+]] { ; CHECK-NEXT: ret i1 false ; %sm = tail call i1 @llvm.aarch64.sme.in.streaming.mode()