[llvm-branch-commits] [llvm] [ADT] Use range-based helper functions in SmallSet (PR #108585)

2024-09-15 Thread Nikita Popov via llvm-branch-commits


@@ -234,19 +225,12 @@ class SmallSet {
   /// Check if the SmallSet contains the given element.
   bool contains(const T &V) const {
 if (isSmall())
-  return vfind(V) != Vector.end();
-return Set.find(V) != Set.end();
+  return llvm::is_contained(Vector, V);
+return llvm::is_contained(Set, V);

nikic wrote:

Please do not use is_contained with fast set types.

https://github.com/llvm/llvm-project/pull/108585
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Use range-based helper functions in SmallSet (PR #108585)

2024-09-15 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic edited https://github.com/llvm/llvm-project/pull/108585
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ADT] Use range-based helper functions in SmallSet (PR #108585)

2024-09-15 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic edited https://github.com/llvm/llvm-project/pull/108585
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [Attributor] Take the address space from addrspacecast directly (PR #108258)

2024-09-15 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

> If the value to be analyzed is directly from addrspacecast, we take the source
address space directly. 

I don't think this is valid in general. You are allow to speculatively produce 
invalid addrspacecasts. For example:

```
__generic int* g_ptr = ...;
__local int* l_ptr = (__local int*) g_ptr;
if (is_shared(g_ptr)) 
  *l_ptr = 1;


```


https://github.com/llvm/llvm-project/pull/108258
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] Fix evaluation of the unsigned enumeration values, #108766 (PR #108768)

2024-09-15 Thread Dmitry Fursov via llvm-branch-commits

https://github.com/fursov created 
https://github.com/llvm/llvm-project/pull/108768

If the type of an enumeration is not native (e.g. uint8_t) but is unsigned then 
evaluation of the value might get wrong: for values bigger than half of type 
range the return value will be negative. This happens because for non-native 
enum types the TypeKind is ELABORATED. To get the real integer type, the 
conversion to canonical type is required before the enum_value() function can 
decide about type being signed or unsigned.

>From 7b21ad1d04153c3b27850626403e33eda85d9c3d Mon Sep 17 00:00:00 2001
From: Dmitry Fursov 
Date: Sun, 15 Sep 2024 18:14:48 +0300
Subject: [PATCH] Fix evaluation of the unsigned enumeration values

If the type of an enumeration is not native (e.g. uint8_t) but
is unsigned then evaluation of the value might get wrong: for
values bigger than half of type range the return value will be
negative. This happens because for non-native enum types the TypeKind
is ELABORATED. To get the real integer type, the conversion to
canonical type is required before the enum_value() function can
decide about type being signed or unsigned.
---
 clang/bindings/python/clang/cindex.py |  2 ++
 .../python/tests/cindex/test_cursor.py| 19 +++
 2 files changed, 21 insertions(+)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 754f03d718e882..67215f0b7fdcb7 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -1831,6 +1831,8 @@ def enum_value(self):
 underlying_type = self.type
 if underlying_type.kind == TypeKind.ENUM:
 underlying_type = underlying_type.get_declaration().enum_type
+if underlying_type.kind == TypeKind.ELABORATED:
+underlying_type = underlying_type.get_canonical()
 if underlying_type.kind in (
 TypeKind.CHAR_U,
 TypeKind.UCHAR,
diff --git a/clang/bindings/python/tests/cindex/test_cursor.py 
b/clang/bindings/python/tests/cindex/test_cursor.py
index 84cd8139418447..5cb3e638c94a60 100644
--- a/clang/bindings/python/tests/cindex/test_cursor.py
+++ b/clang/bindings/python/tests/cindex/test_cursor.py
@@ -511,6 +511,25 @@ def test_enum_values_cpp(self):
 self.assertEqual(ham.kind, CursorKind.ENUM_CONSTANT_DECL)
 self.assertEqual(ham.enum_value, 0x100)
 
+def test_enum_values_on_elaborated_type(self):
+tu = get_tu(
+"using myUType = unsigned char; enum TEST : myUType { SPAM = 1, 
HAM = 0xff;", lang="cpp"
+)
+enum = get_cursor(tu, "TEST")
+self.assertIsNotNone(enum)
+
+self.assertEqual(enum.kind, CursorKind.ENUM_DECL)
+
+enum_constants = list(enum.get_children())
+self.assertEqual(len(enum_constants), 2)
+
+spam, ham = enum_constants
+
+self.assertEqual(spam.kind, CursorKind.ENUM_CONSTANT_DECL)
+self.assertEqual(spam.enum_value, 1)
+self.assertEqual(ham.kind, CursorKind.ENUM_CONSTANT_DECL)
+self.assertEqual(ham.enum_value, 255)
+
 def test_annotation_attribute(self):
 tu = get_tu(
 'int foo (void) __attribute__ ((annotate("here be annotation 
attribute")));'

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] Fix evaluation of the unsigned enumeration values, #108766 (PR #108768)

2024-09-15 Thread via llvm-branch-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment โ€œPingโ€. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/108768
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] Fix evaluation of the unsigned enumeration values, #108766 (PR #108768)

2024-09-15 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Dmitry Fursov (fursov)


Changes

If the type of an enumeration is not native (e.g. uint8_t) but is unsigned then 
evaluation of the value might get wrong: for values bigger than half of type 
range the return value will be negative. This happens because for non-native 
enum types the TypeKind is ELABORATED. To get the real integer type, the 
conversion to canonical type is required before the enum_value() function can 
decide about type being signed or unsigned.

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


2 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+2) 
- (modified) clang/bindings/python/tests/cindex/test_cursor.py (+19) 


``diff
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 754f03d718e882..67215f0b7fdcb7 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -1831,6 +1831,8 @@ def enum_value(self):
 underlying_type = self.type
 if underlying_type.kind == TypeKind.ENUM:
 underlying_type = underlying_type.get_declaration().enum_type
+if underlying_type.kind == TypeKind.ELABORATED:
+underlying_type = underlying_type.get_canonical()
 if underlying_type.kind in (
 TypeKind.CHAR_U,
 TypeKind.UCHAR,
diff --git a/clang/bindings/python/tests/cindex/test_cursor.py 
b/clang/bindings/python/tests/cindex/test_cursor.py
index 84cd8139418447..5cb3e638c94a60 100644
--- a/clang/bindings/python/tests/cindex/test_cursor.py
+++ b/clang/bindings/python/tests/cindex/test_cursor.py
@@ -511,6 +511,25 @@ def test_enum_values_cpp(self):
 self.assertEqual(ham.kind, CursorKind.ENUM_CONSTANT_DECL)
 self.assertEqual(ham.enum_value, 0x100)
 
+def test_enum_values_on_elaborated_type(self):
+tu = get_tu(
+"using myUType = unsigned char; enum TEST : myUType { SPAM = 1, 
HAM = 0xff;", lang="cpp"
+)
+enum = get_cursor(tu, "TEST")
+self.assertIsNotNone(enum)
+
+self.assertEqual(enum.kind, CursorKind.ENUM_DECL)
+
+enum_constants = list(enum.get_children())
+self.assertEqual(len(enum_constants), 2)
+
+spam, ham = enum_constants
+
+self.assertEqual(spam.kind, CursorKind.ENUM_CONSTANT_DECL)
+self.assertEqual(spam.enum_value, 1)
+self.assertEqual(ham.kind, CursorKind.ENUM_CONSTANT_DECL)
+self.assertEqual(ham.enum_value, 255)
+
 def test_annotation_attribute(self):
 tu = get_tu(
 'int foo (void) __attribute__ ((annotate("here be annotation 
attribute")));'

``




https://github.com/llvm/llvm-project/pull/108768
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] f5d4293 - Revert "[HIP] Use original file path for CUID (#107734)"

2024-09-15 Thread via llvm-branch-commits

Author: dyung
Date: 2024-09-15T09:37:28-07:00
New Revision: f5d42938f209cb1f814ef8db78c7755fe31e2c5c

URL: 
https://github.com/llvm/llvm-project/commit/f5d42938f209cb1f814ef8db78c7755fe31e2c5c
DIFF: 
https://github.com/llvm/llvm-project/commit/f5d42938f209cb1f814ef8db78c7755fe31e2c5c.diff

LOG: Revert "[HIP] Use original file path for CUID (#107734)"

This reverts commit 9fc789d922ddf1c849f62bdfbe034f3cd9354967.

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
clang/test/Driver/hip-cuid-hash.hip

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 758fd744fd46c2..efe398dd531da7 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3034,7 +3034,10 @@ class OffloadingActionBuilder final {
   else if (UseCUID == CUID_Hash) {
 llvm::MD5 Hasher;
 llvm::MD5::MD5Result Hash;
-Hasher.update(IA->getInputArg().getValue());
+SmallString<256> RealPath;
+llvm::sys::fs::real_path(IA->getInputArg().getValue(), RealPath,
+ /*expand_tilde=*/true);
+Hasher.update(RealPath);
 for (auto *A : Args) {
   if (A->getOption().matches(options::OPT_INPUT))
 continue;

diff  --git a/clang/test/Driver/hip-cuid-hash.hip 
b/clang/test/Driver/hip-cuid-hash.hip
index 6987a98470c6c7..103a1cbf26d50a 100644
--- a/clang/test/Driver/hip-cuid-hash.hip
+++ b/clang/test/Driver/hip-cuid-hash.hip
@@ -1,15 +1,13 @@
 // Check CUID generated by hash.
 // The same CUID is generated for the same file with the same options.
 
-// RUN: cd %S
-
 // RUN: %clang -### -x hip --target=x86_64-unknown-linux-gnu 
--no-offload-new-driver \
 // RUN:   --offload-arch=gfx906 -c -nogpuinc -nogpulib -fuse-cuid=hash \
-// RUN:   Inputs/hip_multiple_inputs/a.cu >%t.out 2>&1
+// RUN:   %S/Inputs/hip_multiple_inputs/a.cu >%t.out 2>&1
 
 // RUN: %clang -### -x hip --target=x86_64-unknown-linux-gnu 
--no-offload-new-driver \
 // RUN:   --offload-arch=gfx906 -c -nogpuinc -nogpulib -fuse-cuid=hash \
-// RUN:   Inputs/hip_multiple_inputs/a.cu >>%t.out 2>&1
+// RUN:   %S/Inputs/hip_multiple_inputs/a.cu >>%t.out 2>&1
 
 // RUN: FileCheck %s -check-prefixes=SAME -input-file %t.out
 
@@ -18,15 +16,15 @@
 
 // RUN: %clang -### -x hip --target=x86_64-unknown-linux-gnu -DX=1 
--no-offload-new-driver \
 // RUN:   --offload-arch=gfx906 -c -nogpuinc -nogpulib -fuse-cuid=hash \
-// RUN:   Inputs/hip_multiple_inputs/a.cu >%t.out 2>&1
+// RUN:   %S/Inputs/hip_multiple_inputs/a.cu >%t.out 2>&1
 
 // RUN: %clang -### -x hip --target=x86_64-unknown-linux-gnu -DX=2 
--no-offload-new-driver \
 // RUN:   --offload-arch=gfx906 -c -nogpuinc -nogpulib -fuse-cuid=hash \
-// RUN:   Inputs/../Inputs/hip_multiple_inputs/a.cu >>%t.out 2>&1
+// RUN:   %S/Inputs/../Inputs/hip_multiple_inputs/a.cu >>%t.out 2>&1
 
 // RUN: FileCheck %s -check-prefixes=DIFF -input-file %t.out
 
-// SAME: "-cc1"{{.*}} "-target-cpu" "gfx906" 
{{.*}}"-cuid=[[CUID:3c08c1ef86ef439d]]"
+// SAME: "-cc1"{{.*}} "-target-cpu" "gfx906" {{.*}}"-cuid=[[CUID:[0-9a-f]+]]"
 // SAME: "-cc1"{{.*}} "-target-cpu" "gfx906" {{.*}}"-cuid=[[CUID]]"
 
 // DIFF: "-cc1"{{.*}} "-target-cpu" "gfx906" {{.*}}"-cuid=[[CUID:[0-9a-f]+]]"



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [mlir] [MLIR][OpenMP][Docs] NFC: Document clause-based op representation (PR #107234)

2024-09-15 Thread Tom Eccles via llvm-branch-commits

https://github.com/tblah approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/107234
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/19.x: [X86] Fix missing check of rotate <-> shift equivilence (Issue 108722) (PR #108783)

2024-09-15 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/108783
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/19.x: [X86] Fix missing check of rotate <-> shift equivilence (Issue 108722) (PR #108783)

2024-09-15 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/108783

Backport 1c378d2b145578948942512f9d6985e37659d013 
81279bf97f187eee0446af00d8ae9ec32a22e878

Requested by: @goldsteinn

>From 4c558a8d535a48d0588671d1574bc5a70478adce Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Sun, 15 Sep 2024 09:00:28 -0700
Subject: [PATCH 1/2] [X86] Add test for issue 108722; NFC

(cherry picked from commit 1c378d2b145578948942512f9d6985e37659d013)
---
 llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll | 24 +++
 1 file changed, 24 insertions(+)

diff --git a/llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll 
b/llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll
index 67070b989786db..799b5417857575 100644
--- a/llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll
+++ b/llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll
@@ -994,6 +994,30 @@ define i1 @shr_to_rotate_eq_i32_s5(i32 %x) {
   ret i1 %r
 }
 
+define i32 @issue108722(i32 %0) {
+; CHECK-NOBMI-LABEL: issue108722:
+; CHECK-NOBMI:   # %bb.0:
+; CHECK-NOBMI-NEXT:movzbl %dil, %ecx
+; CHECK-NOBMI-NEXT:shrl $24, %edi
+; CHECK-NOBMI-NEXT:xorl %eax, %eax
+; CHECK-NOBMI-NEXT:cmpl %edi, %ecx
+; CHECK-NOBMI-NEXT:sete %al
+; CHECK-NOBMI-NEXT:retq
+;
+; CHECK-BMI2-LABEL: issue108722:
+; CHECK-BMI2:   # %bb.0:
+; CHECK-BMI2-NEXT:rorxl $8, %edi, %ecx
+; CHECK-BMI2-NEXT:xorl %eax, %eax
+; CHECK-BMI2-NEXT:cmpl %edi, %ecx
+; CHECK-BMI2-NEXT:sete %al
+; CHECK-BMI2-NEXT:retq
+  %2 = tail call i32 @llvm.fshl.i32(i32 %0, i32 %0, i32 24)
+  %3 = icmp eq i32 %2, %0
+  %4 = zext i1 %3 to i32
+  ret i32 %4
+}
+
+
 ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add 
tests below this line:
 ; CHECK-AVX: {{.*}}
 ; CHECK-NOBMI-SSE2: {{.*}}

>From 7aaa237104f50ba921d05a371be00636ed700e14 Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Sun, 15 Sep 2024 09:00:34 -0700
Subject: [PATCH 2/2] [X86] Fix missing check of rotate <-> shift equivilence
 (Issue 108722)

Previous code was checking that rotate and shift where equivilent when
transforming shift -> rotate but not the other way around.

Closes #108767

(cherry picked from commit 81279bf97f187eee0446af00d8ae9ec32a22e878)
---
 llvm/lib/Target/X86/X86ISelLowering.cpp   | 2 +-
 llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 5a9d679d7002cb..45989bcd07d37e 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -3415,7 +3415,7 @@ unsigned 
X86TargetLowering::preferedOpcodeForCmpEqPiecesOfOperand(
 
   // We prefer rotate for vectors of if we won't get a zext mask with SRL
   // (PreferRotate will be set in the latter case).
-  if (PreferRotate || VT.isVector())
+  if (PreferRotate || !MayTransformRotate || VT.isVector())
 return ShiftOpc;
 
   // Non-vector type and we have a zext mask with SRL.
diff --git a/llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll 
b/llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll
index 799b5417857575..227de9ad0ab690 100644
--- a/llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll
+++ b/llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll
@@ -997,8 +997,8 @@ define i1 @shr_to_rotate_eq_i32_s5(i32 %x) {
 define i32 @issue108722(i32 %0) {
 ; CHECK-NOBMI-LABEL: issue108722:
 ; CHECK-NOBMI:   # %bb.0:
-; CHECK-NOBMI-NEXT:movzbl %dil, %ecx
-; CHECK-NOBMI-NEXT:shrl $24, %edi
+; CHECK-NOBMI-NEXT:movl %edi, %ecx
+; CHECK-NOBMI-NEXT:roll $24, %ecx
 ; CHECK-NOBMI-NEXT:xorl %eax, %eax
 ; CHECK-NOBMI-NEXT:cmpl %edi, %ecx
 ; CHECK-NOBMI-NEXT:sete %al

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] release/19.x: [X86] Fix missing check of rotate <-> shift equivilence (Issue 108722) (PR #108783)

2024-09-15 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: None (llvmbot)


Changes

Backport 1c378d2b145578948942512f9d6985e37659d013 
81279bf97f187eee0446af00d8ae9ec32a22e878

Requested by: @goldsteinn

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


2 Files Affected:

- (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+1-1) 
- (modified) llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll (+24) 


``diff
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 5a9d679d7002cb..45989bcd07d37e 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -3415,7 +3415,7 @@ unsigned 
X86TargetLowering::preferedOpcodeForCmpEqPiecesOfOperand(
 
   // We prefer rotate for vectors of if we won't get a zext mask with SRL
   // (PreferRotate will be set in the latter case).
-  if (PreferRotate || VT.isVector())
+  if (PreferRotate || !MayTransformRotate || VT.isVector())
 return ShiftOpc;
 
   // Non-vector type and we have a zext mask with SRL.
diff --git a/llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll 
b/llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll
index 67070b989786db..227de9ad0ab690 100644
--- a/llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll
+++ b/llvm/test/CodeGen/X86/cmp-shiftX-maskX.ll
@@ -994,6 +994,30 @@ define i1 @shr_to_rotate_eq_i32_s5(i32 %x) {
   ret i1 %r
 }
 
+define i32 @issue108722(i32 %0) {
+; CHECK-NOBMI-LABEL: issue108722:
+; CHECK-NOBMI:   # %bb.0:
+; CHECK-NOBMI-NEXT:movl %edi, %ecx
+; CHECK-NOBMI-NEXT:roll $24, %ecx
+; CHECK-NOBMI-NEXT:xorl %eax, %eax
+; CHECK-NOBMI-NEXT:cmpl %edi, %ecx
+; CHECK-NOBMI-NEXT:sete %al
+; CHECK-NOBMI-NEXT:retq
+;
+; CHECK-BMI2-LABEL: issue108722:
+; CHECK-BMI2:   # %bb.0:
+; CHECK-BMI2-NEXT:rorxl $8, %edi, %ecx
+; CHECK-BMI2-NEXT:xorl %eax, %eax
+; CHECK-BMI2-NEXT:cmpl %edi, %ecx
+; CHECK-BMI2-NEXT:sete %al
+; CHECK-BMI2-NEXT:retq
+  %2 = tail call i32 @llvm.fshl.i32(i32 %0, i32 %0, i32 24)
+  %3 = icmp eq i32 %2, %0
+  %4 = zext i1 %3 to i32
+  ret i32 %4
+}
+
+
 ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add 
tests below this line:
 ; CHECK-AVX: {{.*}}
 ; CHECK-NOBMI-SSE2: {{.*}}

``




https://github.com/llvm/llvm-project/pull/108783
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [TargetTransformInfo] Remove `getFlatAddressSpace` (PR #108787)

2024-09-15 Thread Shilei Tian via llvm-branch-commits

https://github.com/shiltian created 
https://github.com/llvm/llvm-project/pull/108787

This has been moved to `DataLayout`.

>From 8db0d52053b0cde8be13ddb6c669b6b262eefdf8 Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Sun, 15 Sep 2024 23:06:14 -0400
Subject: [PATCH] [TargetTransformInfo] Remove `getFlatAddressSpace`

This has been moved to `DataLayout`.
---
 .../llvm/Analysis/TargetTransformInfo.h   | 21 ---
 .../llvm/Analysis/TargetTransformInfoImpl.h   |  2 --
 llvm/include/llvm/CodeGen/BasicTTIImpl.h  |  5 -
 llvm/lib/Analysis/TargetTransformInfo.cpp |  4 
 .../Target/AMDGPU/AMDGPUTargetTransformInfo.h |  8 ---
 .../Target/NVPTX/NVPTXTargetTransformInfo.h   |  4 
 .../Transforms/Scalar/InferAddressSpaces.cpp  |  2 +-
 7 files changed, 1 insertion(+), 45 deletions(-)

diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h 
b/llvm/include/llvm/Analysis/TargetTransformInfo.h
index b2124c6106198e..e5986225b6fc32 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfo.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h
@@ -451,24 +451,6 @@ class TargetTransformInfo {
   /// Return false if a \p AS0 address cannot possibly alias a \p AS1 address.
   bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const;
 
-  /// Returns the address space ID for a target's 'flat' address space. Note
-  /// this is not necessarily the same as addrspace(0), which LLVM sometimes
-  /// refers to as the generic address space. The flat address space is a
-  /// generic address space that can be used access multiple segments of memory
-  /// with different address spaces. Access of a memory location through a
-  /// pointer with this address space is expected to be legal but slower
-  /// compared to the same memory location accessed through a pointer with a
-  /// different address space.
-  //
-  /// This is for targets with different pointer representations which can
-  /// be converted with the addrspacecast instruction. If a pointer is 
converted
-  /// to this address space, optimizations should attempt to replace the access
-  /// with the source address space.
-  ///
-  /// \returns ~0u if the target does not have such a flat address space to
-  /// optimize away.
-  unsigned getFlatAddressSpace() const;
-
   /// Return any intrinsic address operand indexes which may be rewritten if
   /// they use a flat address space pointer.
   ///
@@ -1836,7 +1818,6 @@ class TargetTransformInfo::Concept {
   virtual bool isAlwaysUniform(const Value *V) = 0;
   virtual bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const = 0;
   virtual bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const = 0;
-  virtual unsigned getFlatAddressSpace() = 0;
   virtual bool collectFlatAddressOperands(SmallVectorImpl &OpIndexes,
   Intrinsic::ID IID) const = 0;
   virtual bool isNoopAddrSpaceCast(unsigned FromAS, unsigned ToAS) const = 0;
@@ -2263,8 +2244,6 @@ class TargetTransformInfo::Model final : public 
TargetTransformInfo::Concept {
 return Impl.addrspacesMayAlias(AS0, AS1);
   }
 
-  unsigned getFlatAddressSpace() override { return Impl.getFlatAddressSpace(); 
}
-
   bool collectFlatAddressOperands(SmallVectorImpl &OpIndexes,
   Intrinsic::ID IID) const override {
 return Impl.collectFlatAddressOperands(OpIndexes, IID);
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h 
b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
index 90eef93a2a54d5..192a1c15347dc7 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -115,8 +115,6 @@ class TargetTransformInfoImplBase {
 return true;
   }
 
-  unsigned getFlatAddressSpace() const { return -1; }
-
   bool collectFlatAddressOperands(SmallVectorImpl &OpIndexes,
   Intrinsic::ID IID) const {
 return false;
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h 
b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index 50dc7d5c54c54a..05b0e5844ac5d5 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -292,11 +292,6 @@ class BasicTTIImplBase : public 
TargetTransformInfoImplCRTPBase {
 return true;
   }
 
-  unsigned getFlatAddressSpace() {
-// Return an invalid address space.
-return -1;
-  }
-
   bool collectFlatAddressOperands(SmallVectorImpl &OpIndexes,
   Intrinsic::ID IID) const {
 return false;
diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp 
b/llvm/lib/Analysis/TargetTransformInfo.cpp
index 2c26493bd3f1ca..5eb6be7a362cb5 100644
--- a/llvm/lib/Analysis/TargetTransformInfo.cpp
+++ b/llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -305,10 +305,6 @@ bool 
llvm::TargetTransformInfo::addrspacesMayAlias(unsigned FromAS,
   return TTIImpl->addrspacesMayAlias(FromAS, ToAS);
 }
 
-unsigned TargetTransformInfo::getFlatAddressSpace() 

[llvm-branch-commits] [llvm] [TargetTransformInfo] Remove `getFlatAddressSpace` (PR #108787)

2024-09-15 Thread Shilei Tian via llvm-branch-commits

https://github.com/shiltian ready_for_review 
https://github.com/llvm/llvm-project/pull/108787
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [TargetTransformInfo] Remove `getFlatAddressSpace` (PR #108787)

2024-09-15 Thread Shilei Tian via llvm-branch-commits

shiltian wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/108787?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#108787** https://app.graphite.dev/github/pr/llvm/llvm-project/108787?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> ๐Ÿ‘ˆ
* **#108786** https://app.graphite.dev/github/pr/llvm/llvm-project/108786?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`

This stack of pull requests is managed by Graphite. https://stacking.dev/?utm_source=stack-comment";>Learn more about 
stacking.


 Join @shiltian and the rest of your teammates on https://graphite.dev?utm-source=stack-comment";>https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="11px" height="11px"/> Graphite
  

https://github.com/llvm/llvm-project/pull/108787
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [TargetTransformInfo] Remove `getFlatAddressSpace` (PR #108787)

2024-09-15 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-backend-nvptx

Author: Shilei Tian (shiltian)


Changes

This has been moved to `DataLayout`.

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


7 Files Affected:

- (modified) llvm/include/llvm/Analysis/TargetTransformInfo.h (-21) 
- (modified) llvm/include/llvm/Analysis/TargetTransformInfoImpl.h (-2) 
- (modified) llvm/include/llvm/CodeGen/BasicTTIImpl.h (-5) 
- (modified) llvm/lib/Analysis/TargetTransformInfo.cpp (-4) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.h (-8) 
- (modified) llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.h (-4) 
- (modified) llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp (+1-1) 


``diff
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h 
b/llvm/include/llvm/Analysis/TargetTransformInfo.h
index b2124c6106198e..e5986225b6fc32 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfo.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h
@@ -451,24 +451,6 @@ class TargetTransformInfo {
   /// Return false if a \p AS0 address cannot possibly alias a \p AS1 address.
   bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const;
 
-  /// Returns the address space ID for a target's 'flat' address space. Note
-  /// this is not necessarily the same as addrspace(0), which LLVM sometimes
-  /// refers to as the generic address space. The flat address space is a
-  /// generic address space that can be used access multiple segments of memory
-  /// with different address spaces. Access of a memory location through a
-  /// pointer with this address space is expected to be legal but slower
-  /// compared to the same memory location accessed through a pointer with a
-  /// different address space.
-  //
-  /// This is for targets with different pointer representations which can
-  /// be converted with the addrspacecast instruction. If a pointer is 
converted
-  /// to this address space, optimizations should attempt to replace the access
-  /// with the source address space.
-  ///
-  /// \returns ~0u if the target does not have such a flat address space to
-  /// optimize away.
-  unsigned getFlatAddressSpace() const;
-
   /// Return any intrinsic address operand indexes which may be rewritten if
   /// they use a flat address space pointer.
   ///
@@ -1836,7 +1818,6 @@ class TargetTransformInfo::Concept {
   virtual bool isAlwaysUniform(const Value *V) = 0;
   virtual bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const = 0;
   virtual bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const = 0;
-  virtual unsigned getFlatAddressSpace() = 0;
   virtual bool collectFlatAddressOperands(SmallVectorImpl &OpIndexes,
   Intrinsic::ID IID) const = 0;
   virtual bool isNoopAddrSpaceCast(unsigned FromAS, unsigned ToAS) const = 0;
@@ -2263,8 +2244,6 @@ class TargetTransformInfo::Model final : public 
TargetTransformInfo::Concept {
 return Impl.addrspacesMayAlias(AS0, AS1);
   }
 
-  unsigned getFlatAddressSpace() override { return Impl.getFlatAddressSpace(); 
}
-
   bool collectFlatAddressOperands(SmallVectorImpl &OpIndexes,
   Intrinsic::ID IID) const override {
 return Impl.collectFlatAddressOperands(OpIndexes, IID);
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h 
b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
index 90eef93a2a54d5..192a1c15347dc7 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -115,8 +115,6 @@ class TargetTransformInfoImplBase {
 return true;
   }
 
-  unsigned getFlatAddressSpace() const { return -1; }
-
   bool collectFlatAddressOperands(SmallVectorImpl &OpIndexes,
   Intrinsic::ID IID) const {
 return false;
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h 
b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index 50dc7d5c54c54a..05b0e5844ac5d5 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -292,11 +292,6 @@ class BasicTTIImplBase : public 
TargetTransformInfoImplCRTPBase {
 return true;
   }
 
-  unsigned getFlatAddressSpace() {
-// Return an invalid address space.
-return -1;
-  }
-
   bool collectFlatAddressOperands(SmallVectorImpl &OpIndexes,
   Intrinsic::ID IID) const {
 return false;
diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp 
b/llvm/lib/Analysis/TargetTransformInfo.cpp
index 2c26493bd3f1ca..5eb6be7a362cb5 100644
--- a/llvm/lib/Analysis/TargetTransformInfo.cpp
+++ b/llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -305,10 +305,6 @@ bool 
llvm::TargetTransformInfo::addrspacesMayAlias(unsigned FromAS,
   return TTIImpl->addrspacesMayAlias(FromAS, ToAS);
 }
 
-unsigned TargetTransformInfo::getFlatAddressSpace() const {
-  return TTIImpl->getFlatAddressSpace();
-}
-
 bool TargetTransformInfo:

[llvm-branch-commits] [llvm] [TargetTransformInfo] Remove `getFlatAddressSpace` (PR #108787)

2024-09-15 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

Needs RFC 

https://github.com/llvm/llvm-project/pull/108787
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [Attributor] Use more appropriate approach to check flat address space (PR #108713)

2024-09-15 Thread Shilei Tian via llvm-branch-commits

https://github.com/shiltian edited 
https://github.com/llvm/llvm-project/pull/108713
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [Attributor] Take the address space from addrspacecast directly (PR #108258)

2024-09-15 Thread Shilei Tian via llvm-branch-commits

https://github.com/shiltian updated 
https://github.com/llvm/llvm-project/pull/108258

>From 20e76a5af6fa001617b5c1ebbad2b3965df922f5 Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Wed, 11 Sep 2024 12:23:32 -0400
Subject: [PATCH] [Attributor] Take the address space from addrspacecast
 directly

If the value to be analyzed is directly from addrspacecast, we take the source
address space directly. This is to improve the case where in
`AMDGPUPromoteKernelArgumentsPass`, the kernel argument is promoted by
insertting an addrspacecast directly from a generic pointer. However, during the
analysis, the underlying object will be the generic pointer, instead of the
addrspacecast, thus the inferred address space is the generic one, which is not
ideal.
---
 .../Transforms/IPO/AttributorAttributes.cpp   | 62 ++-
 llvm/test/CodeGen/AMDGPU/aa-as-infer.ll   | 35 +++
 2 files changed, 83 insertions(+), 14 deletions(-)

diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp 
b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 72ac08ec2b6e1c..8860d5a3295a47 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -12587,16 +12587,38 @@ struct AAAddressSpaceImpl : public AAAddressSpace {
   }
 
   ChangeStatus updateImpl(Attributor &A) override {
+unsigned FlatAS = A.getInfoCache().getDL().getFlatAddressSpace();
+assert(FlatAS != InvalidAddressSpace);
 uint32_t OldAddressSpace = AssumedAddressSpace;
-auto *AUO = A.getOrCreateAAFor(getIRPosition(), this,
-DepClassTy::REQUIRED);
-auto Pred = [&](Value &Obj) {
+
+auto CheckAddressSpace = [&](Value &Obj) {
   if (isa(&Obj))
 return true;
+  // If an argument in flat address space has addrspace cast uses, and 
those
+  // casts are same, then we take the dst addrspace.
+  if (auto *Arg = dyn_cast(&Obj)) {
+if (FlatAS != InvalidAddressSpace &&
+Arg->getType()->getPointerAddressSpace() == FlatAS) {
+  unsigned CastAddrSpace = FlatAS;
+  for (auto *U : Arg->users()) {
+auto *ASCI = dyn_cast(U);
+if (!ASCI)
+  continue;
+if (CastAddrSpace != FlatAS &&
+CastAddrSpace != ASCI->getDestAddressSpace())
+  return false;
+CastAddrSpace = ASCI->getDestAddressSpace();
+  }
+  if (CastAddrSpace != FlatAS)
+return takeAddressSpace(CastAddrSpace);
+}
+  }
   return takeAddressSpace(Obj.getType()->getPointerAddressSpace());
 };
 
-if (!AUO->forallUnderlyingObjects(Pred))
+auto *AUO = A.getOrCreateAAFor(getIRPosition(), this,
+DepClassTy::REQUIRED);
+if (!AUO->forallUnderlyingObjects(CheckAddressSpace))
   return indicatePessimisticFixpoint();
 
 return OldAddressSpace == AssumedAddressSpace ? ChangeStatus::UNCHANGED
@@ -12605,17 +12627,22 @@ struct AAAddressSpaceImpl : public AAAddressSpace {
 
   /// See AbstractAttribute::manifest(...).
   ChangeStatus manifest(Attributor &A) override {
-if (getAddressSpace() == InvalidAddressSpace ||
-getAddressSpace() == getAssociatedType()->getPointerAddressSpace())
+unsigned NewAS = getAddressSpace();
+
+if (NewAS == InvalidAddressSpace ||
+NewAS == getAssociatedType()->getPointerAddressSpace())
   return ChangeStatus::UNCHANGED;
 
+unsigned FlatAS = A.getInfoCache().getDL().getFlatAddressSpace();
+assert(FlatAS != InvalidAddressSpace);
+
 Value *AssociatedValue = &getAssociatedValue();
-Value *OriginalValue = peelAddrspacecast(AssociatedValue);
+Value *OriginalValue = peelAddrspacecast(AssociatedValue, FlatAS);
 
 PointerType *NewPtrTy =
-PointerType::get(getAssociatedType()->getContext(), getAddressSpace());
+PointerType::get(getAssociatedType()->getContext(), NewAS);
 bool UseOriginalValue =
-OriginalValue->getType()->getPointerAddressSpace() == 
getAddressSpace();
+OriginalValue->getType()->getPointerAddressSpace() == NewAS;
 
 bool Changed = false;
 
@@ -12675,12 +12702,19 @@ struct AAAddressSpaceImpl : public AAAddressSpace {
 return AssumedAddressSpace == AS;
   }
 
-  static Value *peelAddrspacecast(Value *V) {
-if (auto *I = dyn_cast(V))
-  return peelAddrspacecast(I->getPointerOperand());
+  static Value *peelAddrspacecast(Value *V, unsigned FlatAS) {
+if (auto *I = dyn_cast(V)) {
+  assert(I->getSrcAddressSpace() != FlatAS &&
+ "there should not be flat AS -> non-flat AS");
+  return I->getPointerOperand();
+}
 if (auto *C = dyn_cast(V))
-  if (C->getOpcode() == Instruction::AddrSpaceCast)
-return peelAddrspacecast(C->getOperand(0));
+  if (C->getOpcode() == Instruction::AddrSpaceCast) {
+assert(C->getOperand(0)->getType()->getPointerAd

[llvm-branch-commits] [llvm] [Attributor] Take the address space from addrspacecast directly (PR #108258)

2024-09-15 Thread Shilei Tian via llvm-branch-commits

shiltian wrote:

> > If the value to be analyzed is directly from addrspacecast, we take the 
> > source
> > address space directly.
> 
> I don't think this is valid in general. You are allow to speculatively 
> produce invalid addrspacecasts. For example:
> 
> ```
> __generic int* g_ptr = ...;
> __local int* l_ptr = (__local int*) g_ptr;
> if (is_shared(g_ptr)) 
>   *l_ptr = 1;
> ```

That doesn't matter because the scope is the instruction. In your example here, 
the pointer of the store is already in the specific address space. That will 
not change no matter whether the branch is taken or not. `AAAddressSpace` 
doesn't say `g_ptr` is in what address space. It just changes the pointer 
operand of memory instruction.

https://github.com/llvm/llvm-project/pull/108258
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [TargetTransformInfo] Remove `getFlatAddressSpace` (PR #108787)

2024-09-15 Thread Shilei Tian via llvm-branch-commits

shiltian wrote:

RFC: 
https://discourse.llvm.org/t/nfc-remove-getflataddressspace-from-targettransforminfo/81263

https://github.com/llvm/llvm-project/pull/108787
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [Attributor] Take the address space from addrspacecast directly (PR #108258)

2024-09-15 Thread Shilei Tian via llvm-branch-commits

https://github.com/shiltian updated 
https://github.com/llvm/llvm-project/pull/108258

>From f9d72576e5683154dbc67df051dbd117db539a33 Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Wed, 11 Sep 2024 12:23:32 -0400
Subject: [PATCH] [Attributor] Take the address space from addrspacecast
 directly

If the value to be analyzed is directly from addrspacecast, we take the source
address space directly. This is to improve the case where in
`AMDGPUPromoteKernelArgumentsPass`, the kernel argument is promoted by
insertting an addrspacecast directly from a generic pointer. However, during the
analysis, the underlying object will be the generic pointer, instead of the
addrspacecast, thus the inferred address space is the generic one, which is not
ideal.
---
 .../Transforms/IPO/AttributorAttributes.cpp   | 62 ++-
 llvm/test/CodeGen/AMDGPU/aa-as-infer.ll   | 33 ++
 2 files changed, 81 insertions(+), 14 deletions(-)

diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp 
b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 72ac08ec2b6e1c..b16bd01af8fa6c 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -12587,16 +12587,38 @@ struct AAAddressSpaceImpl : public AAAddressSpace {
   }
 
   ChangeStatus updateImpl(Attributor &A) override {
+unsigned FlatAS = A.getInfoCache().getDL().getFlatAddressSpace();
+assert(FlatAS != InvalidAddressSpace);
 uint32_t OldAddressSpace = AssumedAddressSpace;
-auto *AUO = A.getOrCreateAAFor(getIRPosition(), this,
-DepClassTy::REQUIRED);
-auto Pred = [&](Value &Obj) {
+
+auto CheckAddressSpace = [&](Value &Obj) {
   if (isa(&Obj))
 return true;
+  // If an argument in flat address space only has addrspace cast uses, and
+  // those casts are same, then we take the dst addrspace.
+  if (auto *Arg = dyn_cast(&Obj)) {
+if (FlatAS != InvalidAddressSpace &&
+Arg->getType()->getPointerAddressSpace() == FlatAS) {
+  unsigned CastAddrSpace = FlatAS;
+  for (auto *U : Arg->users()) {
+auto *ASCI = dyn_cast(U);
+if (!ASCI)
+  return takeAddressSpace(Obj.getType()->getPointerAddressSpace());
+if (CastAddrSpace != FlatAS &&
+CastAddrSpace != ASCI->getDestAddressSpace())
+  return false;
+CastAddrSpace = ASCI->getDestAddressSpace();
+  }
+  if (CastAddrSpace != FlatAS)
+return takeAddressSpace(CastAddrSpace);
+}
+  }
   return takeAddressSpace(Obj.getType()->getPointerAddressSpace());
 };
 
-if (!AUO->forallUnderlyingObjects(Pred))
+auto *AUO = A.getOrCreateAAFor(getIRPosition(), this,
+DepClassTy::REQUIRED);
+if (!AUO->forallUnderlyingObjects(CheckAddressSpace))
   return indicatePessimisticFixpoint();
 
 return OldAddressSpace == AssumedAddressSpace ? ChangeStatus::UNCHANGED
@@ -12605,17 +12627,22 @@ struct AAAddressSpaceImpl : public AAAddressSpace {
 
   /// See AbstractAttribute::manifest(...).
   ChangeStatus manifest(Attributor &A) override {
-if (getAddressSpace() == InvalidAddressSpace ||
-getAddressSpace() == getAssociatedType()->getPointerAddressSpace())
+unsigned NewAS = getAddressSpace();
+
+if (NewAS == InvalidAddressSpace ||
+NewAS == getAssociatedType()->getPointerAddressSpace())
   return ChangeStatus::UNCHANGED;
 
+unsigned FlatAS = A.getInfoCache().getDL().getFlatAddressSpace();
+assert(FlatAS != InvalidAddressSpace);
+
 Value *AssociatedValue = &getAssociatedValue();
-Value *OriginalValue = peelAddrspacecast(AssociatedValue);
+Value *OriginalValue = peelAddrspacecast(AssociatedValue, FlatAS);
 
 PointerType *NewPtrTy =
-PointerType::get(getAssociatedType()->getContext(), getAddressSpace());
+PointerType::get(getAssociatedType()->getContext(), NewAS);
 bool UseOriginalValue =
-OriginalValue->getType()->getPointerAddressSpace() == 
getAddressSpace();
+OriginalValue->getType()->getPointerAddressSpace() == NewAS;
 
 bool Changed = false;
 
@@ -12675,12 +12702,19 @@ struct AAAddressSpaceImpl : public AAAddressSpace {
 return AssumedAddressSpace == AS;
   }
 
-  static Value *peelAddrspacecast(Value *V) {
-if (auto *I = dyn_cast(V))
-  return peelAddrspacecast(I->getPointerOperand());
+  static Value *peelAddrspacecast(Value *V, unsigned FlatAS) {
+if (auto *I = dyn_cast(V)) {
+  assert(I->getSrcAddressSpace() != FlatAS &&
+ "there should not be flat AS -> non-flat AS");
+  return I->getPointerOperand();
+}
 if (auto *C = dyn_cast(V))
-  if (C->getOpcode() == Instruction::AddrSpaceCast)
-return peelAddrspacecast(C->getOperand(0));
+  if (C->getOpcode() == Instruction::AddrSpaceCast) 

[llvm-branch-commits] [lld] release/19.x: [lld] select a default eflags for hexagon (#108431) (PR #108661)

2024-09-15 Thread Alexey Karyakin via llvm-branch-commits

https://github.com/quic-akaryaki approved this pull request.


https://github.com/llvm/llvm-project/pull/108661
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [NFC][sanitizer] Switch to `gnu_get_libc_version` (PR #108724)

2024-09-15 Thread Fangrui Song via llvm-branch-commits

MaskRay wrote:

The header gnu/libc-version.h has been in glibc available since 1998. Nice!

https://github.com/llvm/llvm-project/pull/108724
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [NFC][sanitizer] Switch to `gnu_get_libc_version` (PR #108724)

2024-09-15 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay approved this pull request.


https://github.com/llvm/llvm-project/pull/108724
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [NFC][sanitizer] Switch to `gnu_get_libc_version` (PR #108724)

2024-09-15 Thread Fangrui Song via llvm-branch-commits


@@ -198,17 +202,11 @@ bool SetEnv(const char *name, const char *value) {
 
 __attribute__((unused)) static bool GetLibcVersion(int *major, int *minor,
int *patch) {
-#  ifdef _CS_GNU_LIBC_VERSION
-  char buf[64];
-  uptr len = confstr(_CS_GNU_LIBC_VERSION, buf, sizeof(buf));
-  if (len >= sizeof(buf))
-return false;
-  buf[len] = 0;
-  static const char kGLibC[] = "glibc ";
-  if (internal_strncmp(buf, kGLibC, sizeof(kGLibC) - 1) != 0)
-return false;
-  const char *p = buf + sizeof(kGLibC) - 1;
+#  ifdef SANITIZER_GLIBC
+  const char *p = gnu_get_libc_version();
   *major = internal_simple_strtoll(p, &p, 10);
+  // Caller do not expect anything else.

MaskRay wrote:

Caller does not expect

https://github.com/llvm/llvm-project/pull/108724
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [NFC][sanitizer] Switch to `gnu_get_libc_version` (PR #108724)

2024-09-15 Thread Thurston Dang via llvm-branch-commits

https://github.com/thurstond approved this pull request.


https://github.com/llvm/llvm-project/pull/108724
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [sanitizer] Add CHECK that static TLS info is ready (PR #108684)

2024-09-15 Thread Thurston Dang via llvm-branch-commits

https://github.com/thurstond approved this pull request.


https://github.com/llvm/llvm-project/pull/108684
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [sanitizer] Fix partially initialized static TLS range (PR #108685)

2024-09-15 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay approved this pull request.


https://github.com/llvm/llvm-project/pull/108685
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [sanitizer] Add CHECK that static TLS info is ready (PR #108684)

2024-09-15 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay approved this pull request.


https://github.com/llvm/llvm-project/pull/108684
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits