[llvm] [GVN] Handle empty attrs in Expression == (PR #115761)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 12 03:55:26 PST 2024


https://github.com/macurtis-amd updated https://github.com/llvm/llvm-project/pull/115761

>From 0f08b59ccb4837fe817ec69565b6e3659384d4bf Mon Sep 17 00:00:00 2001
From: Matthew Curtis <macurtis at amd.com>
Date: Mon, 11 Nov 2024 13:42:45 -0600
Subject: [PATCH] [GVN] Handle empty attrs in Expression ==

Change-Id: I75e876452af701191d36331703654581c6eb46f2
---
 llvm/lib/Transforms/Scalar/GVN.cpp            |  2 +-
 .../Transforms/GVN/intersect-empty-attr.ll    | 21 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Transforms/GVN/intersect-empty-attr.ll

diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index e27f5a08c85a97..a3df7a0a39e6b2 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -156,7 +156,7 @@ struct llvm::GVNPass::Expression {
       return false;
     if (varargs != other.varargs)
       return false;
-    if (!attrs.isEmpty() && !other.attrs.isEmpty() &&
+    if ((!attrs.isEmpty() || !other.attrs.isEmpty()) &&
         !attrs.intersectWith(type->getContext(), other.attrs).has_value())
       return false;
     return true;
diff --git a/llvm/test/Transforms/GVN/intersect-empty-attr.ll b/llvm/test/Transforms/GVN/intersect-empty-attr.ll
new file mode 100644
index 00000000000000..a2d719e4187581
--- /dev/null
+++ b/llvm/test/Transforms/GVN/intersect-empty-attr.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S -passes=gvn < %s | FileCheck %s
+
+declare i32 @bar() #0
+
+define i32 @foo() {
+; CHECK-LABEL: define i32 @foo() {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TMP0:%.*]] = tail call i32 @bar() #[[ATTR1:[0-9]+]]
+; CHECK-NEXT:    [[TMP1:%.*]] = tail call i32 @bar()
+; CHECK-NEXT:    ret i32 1
+;
+entry:
+  %0 = tail call i32 @bar() #1
+  %1 = tail call i32 @bar()
+  ret i32 1
+}
+
+
+attributes #0 = { memory(none) }
+attributes #1 = { "llvm.assume"="ompx_no_call_asm" }



More information about the llvm-commits mailing list