Skip to content

[HEXAGON] Enable Utilize Mask Instruction Pass only if the Arch #102880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

quic-asaravan
Copy link
Contributor

version is greater than v66

No support for mask instruction before arch version v66

version is greater than v66

No support for mask instruction before arch version v66
@llvmbot
Copy link
Member

llvmbot commented Aug 12, 2024

@llvm/pr-subscribers-backend-hexagon

Author: Abinaya Saravanan (quic-asaravan)

Changes

version is greater than v66

No support for mask instruction before arch version v66


Full diff: https://github.com/llvm/llvm-project/pull/102880.diff

2 Files Affected:

  • (modified) llvm/lib/Target/Hexagon/HexagonMask.cpp (+3)
  • (added) llvm/test/CodeGen/Hexagon/mask-instr.ll (+26)
diff --git a/llvm/lib/Target/Hexagon/HexagonMask.cpp b/llvm/lib/Target/Hexagon/HexagonMask.cpp
index ac9abfa6c12331..d31edc3d299ffe 100644
--- a/llvm/lib/Target/Hexagon/HexagonMask.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonMask.cpp
@@ -90,6 +90,9 @@ bool HexagonMask::runOnMachineFunction(MachineFunction &MF) {
 
   if (!F.hasFnAttribute(Attribute::OptimizeForSize))
     return false;
+  // Mask instruction is available only from v66
+  if (!HST.hasV66Ops())
+    return false;
   // The mask instruction available in v66 can be used to generate values in
   // registers using 2 immediates Eg. to form 0x07fffffc in R0, you would write
   // "R0 = mask(#25,#2)" Since it is a single-word instruction, it takes less
diff --git a/llvm/test/CodeGen/Hexagon/mask-instr.ll b/llvm/test/CodeGen/Hexagon/mask-instr.ll
new file mode 100644
index 00000000000000..ab60a6fcade739
--- /dev/null
+++ b/llvm/test/CodeGen/Hexagon/mask-instr.ll
@@ -0,0 +1,26 @@
+; Enable Utlilize mask instruction pass only on v66 and above.
+; RUN: llc -mv60 -march=hexagon < %s -o /dev/null
+
+target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048"
+target triple = "hexagon"
+
+@b = dso_local local_unnamed_addr global i8 0, align 1
+@a = dso_local local_unnamed_addr global i32 0, align 4
+
+; Function Attrs: cold nounwind optsize memory(readwrite, argmem: none, inaccessiblemem: none)
+define dso_local void @c() local_unnamed_addr {
+entry:
+  %0 = tail call i32 asm "", "=&r"()
+  %and = and i32 %0, 134217727
+  %tobool.not = icmp eq i32 %and, 0
+  br i1 %tobool.not, label %if.end, label %if.then
+
+if.then:                                          ; preds = %entry
+  %1 = load i8, ptr @b, align 1
+  %loadedv = zext nneg i8 %1 to i32
+  store i32 %loadedv, ptr @a, align 4
+  br label %if.end
+
+if.end:                                           ; preds = %if.then, %entry
+  ret void
+}

@quic-asaravan
Copy link
Contributor Author

@androm3da @SundeepKushwaha @iajbar Can you pls review this ?

@quic-asaravan quic-asaravan merged commit 86ef9ee into llvm:main Aug 13, 2024
10 checks passed
@iajbar iajbar self-requested a review August 15, 2024 00:03
@quic-asaravan quic-asaravan deleted the Mask-Instr1 branch August 28, 2024 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants