[llvm-branch-commits] [clang] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-29 Thread via llvm-branch-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/90159

>From cd57d28d88e2ccd85ff2c96c07d13c7654265209 Mon Sep 17 00:00:00 2001
From: wanglei 
Date: Tue, 30 Apr 2024 14:29:08 +0800
Subject: [PATCH] Add test to clang/test/Driver/tls-dialect.c

Created using spr 1.3.4
---
 clang/test/Driver/tls-dialect.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Driver/tls-dialect.c b/clang/test/Driver/tls-dialect.c
index a808dd81531ce7..3471b55b0ebae9 100644
--- a/clang/test/Driver/tls-dialect.c
+++ b/clang/test/Driver/tls-dialect.c
@@ -1,3 +1,5 @@
+// RUN: %clang -### --target=loongarch64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
+// RUN: %clang -### --target=loongarch64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-freebsd -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=DESC %s
 // RUN: %clang -### --target=riscv64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
@@ -9,6 +11,8 @@
 // RUN: %clang -### --target=riscv64-android %s 2>&1 | FileCheck 
--check-prefix=DESC %s
 
 /// LTO
+// RUN: %clang -### --target=loongarch64-linux -flto -mtls-dialect=desc %s 
2>&1 | FileCheck --check-prefix=LTO-DESC %s
+// RUN: %clang -### --target=loongarch64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 // RUN: %clang -### --target=riscv64-linux -flto -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=LTO-DESC %s
 // RUN: %clang -### --target=riscv64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 
@@ -18,6 +22,7 @@
 // RUN: not %clang --target=x86_64-apple-macos -mtls-dialect=desc -flto %s 
2>&1 | FileCheck -check-prefix=UNSUPPORTED-TARGET %s
 
 /// Unsupported argument
+// RUN: not %clang -### --target=loongarch64-linux -mtls-dialect=gnu2 %s 2>&1 
| FileCheck --check-prefix=UNSUPPORTED-ARG %s
 // RUN: not %clang -### --target=riscv64-linux -mtls-dialect=gnu2 %s 2>&1 | 
FileCheck --check-prefix=UNSUPPORTED-ARG %s
 
 // DESC:   "-cc1" {{.*}}"-enable-tlsdesc"

___
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] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-29 Thread via llvm-branch-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/90159

>From cd57d28d88e2ccd85ff2c96c07d13c7654265209 Mon Sep 17 00:00:00 2001
From: wanglei 
Date: Tue, 30 Apr 2024 14:29:08 +0800
Subject: [PATCH] Add test to clang/test/Driver/tls-dialect.c

Created using spr 1.3.4
---
 clang/test/Driver/tls-dialect.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Driver/tls-dialect.c b/clang/test/Driver/tls-dialect.c
index a808dd81531ce7..3471b55b0ebae9 100644
--- a/clang/test/Driver/tls-dialect.c
+++ b/clang/test/Driver/tls-dialect.c
@@ -1,3 +1,5 @@
+// RUN: %clang -### --target=loongarch64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
+// RUN: %clang -### --target=loongarch64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-freebsd -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=DESC %s
 // RUN: %clang -### --target=riscv64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
@@ -9,6 +11,8 @@
 // RUN: %clang -### --target=riscv64-android %s 2>&1 | FileCheck 
--check-prefix=DESC %s
 
 /// LTO
+// RUN: %clang -### --target=loongarch64-linux -flto -mtls-dialect=desc %s 
2>&1 | FileCheck --check-prefix=LTO-DESC %s
+// RUN: %clang -### --target=loongarch64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 // RUN: %clang -### --target=riscv64-linux -flto -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=LTO-DESC %s
 // RUN: %clang -### --target=riscv64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 
@@ -18,6 +22,7 @@
 // RUN: not %clang --target=x86_64-apple-macos -mtls-dialect=desc -flto %s 
2>&1 | FileCheck -check-prefix=UNSUPPORTED-TARGET %s
 
 /// Unsupported argument
+// RUN: not %clang -### --target=loongarch64-linux -mtls-dialect=gnu2 %s 2>&1 
| FileCheck --check-prefix=UNSUPPORTED-ARG %s
 // RUN: not %clang -### --target=riscv64-linux -mtls-dialect=gnu2 %s 2>&1 | 
FileCheck --check-prefix=UNSUPPORTED-ARG %s
 
 // DESC:   "-cc1" {{.*}}"-enable-tlsdesc"

___
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] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-29 Thread via llvm-branch-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/90159

>From cd57d28d88e2ccd85ff2c96c07d13c7654265209 Mon Sep 17 00:00:00 2001
From: wanglei 
Date: Tue, 30 Apr 2024 14:29:08 +0800
Subject: [PATCH] Add test to clang/test/Driver/tls-dialect.c

Created using spr 1.3.4
---
 clang/test/Driver/tls-dialect.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Driver/tls-dialect.c b/clang/test/Driver/tls-dialect.c
index a808dd81531ce7..3471b55b0ebae9 100644
--- a/clang/test/Driver/tls-dialect.c
+++ b/clang/test/Driver/tls-dialect.c
@@ -1,3 +1,5 @@
+// RUN: %clang -### --target=loongarch64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
+// RUN: %clang -### --target=loongarch64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-freebsd -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=DESC %s
 // RUN: %clang -### --target=riscv64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
@@ -9,6 +11,8 @@
 // RUN: %clang -### --target=riscv64-android %s 2>&1 | FileCheck 
--check-prefix=DESC %s
 
 /// LTO
+// RUN: %clang -### --target=loongarch64-linux -flto -mtls-dialect=desc %s 
2>&1 | FileCheck --check-prefix=LTO-DESC %s
+// RUN: %clang -### --target=loongarch64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 // RUN: %clang -### --target=riscv64-linux -flto -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=LTO-DESC %s
 // RUN: %clang -### --target=riscv64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 
@@ -18,6 +22,7 @@
 // RUN: not %clang --target=x86_64-apple-macos -mtls-dialect=desc -flto %s 
2>&1 | FileCheck -check-prefix=UNSUPPORTED-TARGET %s
 
 /// Unsupported argument
+// RUN: not %clang -### --target=loongarch64-linux -mtls-dialect=gnu2 %s 2>&1 
| FileCheck --check-prefix=UNSUPPORTED-ARG %s
 // RUN: not %clang -### --target=riscv64-linux -mtls-dialect=gnu2 %s 2>&1 | 
FileCheck --check-prefix=UNSUPPORTED-ARG %s
 
 // DESC:   "-cc1" {{.*}}"-enable-tlsdesc"

___
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] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-29 Thread via llvm-branch-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/90159

>From cd57d28d88e2ccd85ff2c96c07d13c7654265209 Mon Sep 17 00:00:00 2001
From: wanglei 
Date: Tue, 30 Apr 2024 14:29:08 +0800
Subject: [PATCH] Add test to clang/test/Driver/tls-dialect.c

Created using spr 1.3.4
---
 clang/test/Driver/tls-dialect.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Driver/tls-dialect.c b/clang/test/Driver/tls-dialect.c
index a808dd81531ce7..3471b55b0ebae9 100644
--- a/clang/test/Driver/tls-dialect.c
+++ b/clang/test/Driver/tls-dialect.c
@@ -1,3 +1,5 @@
+// RUN: %clang -### --target=loongarch64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
+// RUN: %clang -### --target=loongarch64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-freebsd -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=DESC %s
 // RUN: %clang -### --target=riscv64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
@@ -9,6 +11,8 @@
 // RUN: %clang -### --target=riscv64-android %s 2>&1 | FileCheck 
--check-prefix=DESC %s
 
 /// LTO
+// RUN: %clang -### --target=loongarch64-linux -flto -mtls-dialect=desc %s 
2>&1 | FileCheck --check-prefix=LTO-DESC %s
+// RUN: %clang -### --target=loongarch64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 // RUN: %clang -### --target=riscv64-linux -flto -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=LTO-DESC %s
 // RUN: %clang -### --target=riscv64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 
@@ -18,6 +22,7 @@
 // RUN: not %clang --target=x86_64-apple-macos -mtls-dialect=desc -flto %s 
2>&1 | FileCheck -check-prefix=UNSUPPORTED-TARGET %s
 
 /// Unsupported argument
+// RUN: not %clang -### --target=loongarch64-linux -mtls-dialect=gnu2 %s 2>&1 
| FileCheck --check-prefix=UNSUPPORTED-ARG %s
 // RUN: not %clang -### --target=riscv64-linux -mtls-dialect=gnu2 %s 2>&1 | 
FileCheck --check-prefix=UNSUPPORTED-ARG %s
 
 // DESC:   "-cc1" {{.*}}"-enable-tlsdesc"

___
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] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-29 Thread via llvm-branch-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/90159

>From cd57d28d88e2ccd85ff2c96c07d13c7654265209 Mon Sep 17 00:00:00 2001
From: wanglei 
Date: Tue, 30 Apr 2024 14:29:08 +0800
Subject: [PATCH] Add test to clang/test/Driver/tls-dialect.c

Created using spr 1.3.4
---
 clang/test/Driver/tls-dialect.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Driver/tls-dialect.c b/clang/test/Driver/tls-dialect.c
index a808dd81531ce7..3471b55b0ebae9 100644
--- a/clang/test/Driver/tls-dialect.c
+++ b/clang/test/Driver/tls-dialect.c
@@ -1,3 +1,5 @@
+// RUN: %clang -### --target=loongarch64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
+// RUN: %clang -### --target=loongarch64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-freebsd -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=DESC %s
 // RUN: %clang -### --target=riscv64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
@@ -9,6 +11,8 @@
 // RUN: %clang -### --target=riscv64-android %s 2>&1 | FileCheck 
--check-prefix=DESC %s
 
 /// LTO
+// RUN: %clang -### --target=loongarch64-linux -flto -mtls-dialect=desc %s 
2>&1 | FileCheck --check-prefix=LTO-DESC %s
+// RUN: %clang -### --target=loongarch64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 // RUN: %clang -### --target=riscv64-linux -flto -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=LTO-DESC %s
 // RUN: %clang -### --target=riscv64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 
@@ -18,6 +22,7 @@
 // RUN: not %clang --target=x86_64-apple-macos -mtls-dialect=desc -flto %s 
2>&1 | FileCheck -check-prefix=UNSUPPORTED-TARGET %s
 
 /// Unsupported argument
+// RUN: not %clang -### --target=loongarch64-linux -mtls-dialect=gnu2 %s 2>&1 
| FileCheck --check-prefix=UNSUPPORTED-ARG %s
 // RUN: not %clang -### --target=riscv64-linux -mtls-dialect=gnu2 %s 2>&1 | 
FileCheck --check-prefix=UNSUPPORTED-ARG %s
 
 // DESC:   "-cc1" {{.*}}"-enable-tlsdesc"

___
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] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-29 Thread via llvm-branch-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/90159

>From cd57d28d88e2ccd85ff2c96c07d13c7654265209 Mon Sep 17 00:00:00 2001
From: wanglei 
Date: Tue, 30 Apr 2024 14:29:08 +0800
Subject: [PATCH] Add test to clang/test/Driver/tls-dialect.c

Created using spr 1.3.4
---
 clang/test/Driver/tls-dialect.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Driver/tls-dialect.c b/clang/test/Driver/tls-dialect.c
index a808dd81531ce7..3471b55b0ebae9 100644
--- a/clang/test/Driver/tls-dialect.c
+++ b/clang/test/Driver/tls-dialect.c
@@ -1,3 +1,5 @@
+// RUN: %clang -### --target=loongarch64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
+// RUN: %clang -### --target=loongarch64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-freebsd -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=DESC %s
 // RUN: %clang -### --target=riscv64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
@@ -9,6 +11,8 @@
 // RUN: %clang -### --target=riscv64-android %s 2>&1 | FileCheck 
--check-prefix=DESC %s
 
 /// LTO
+// RUN: %clang -### --target=loongarch64-linux -flto -mtls-dialect=desc %s 
2>&1 | FileCheck --check-prefix=LTO-DESC %s
+// RUN: %clang -### --target=loongarch64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 // RUN: %clang -### --target=riscv64-linux -flto -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=LTO-DESC %s
 // RUN: %clang -### --target=riscv64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 
@@ -18,6 +22,7 @@
 // RUN: not %clang --target=x86_64-apple-macos -mtls-dialect=desc -flto %s 
2>&1 | FileCheck -check-prefix=UNSUPPORTED-TARGET %s
 
 /// Unsupported argument
+// RUN: not %clang -### --target=loongarch64-linux -mtls-dialect=gnu2 %s 2>&1 
| FileCheck --check-prefix=UNSUPPORTED-ARG %s
 // RUN: not %clang -### --target=riscv64-linux -mtls-dialect=gnu2 %s 2>&1 | 
FileCheck --check-prefix=UNSUPPORTED-ARG %s
 
 // DESC:   "-cc1" {{.*}}"-enable-tlsdesc"

___
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] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-29 Thread via llvm-branch-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/90159

>From cd57d28d88e2ccd85ff2c96c07d13c7654265209 Mon Sep 17 00:00:00 2001
From: wanglei 
Date: Tue, 30 Apr 2024 14:29:08 +0800
Subject: [PATCH] Add test to clang/test/Driver/tls-dialect.c

Created using spr 1.3.4
---
 clang/test/Driver/tls-dialect.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/Driver/tls-dialect.c b/clang/test/Driver/tls-dialect.c
index a808dd81531ce7..3471b55b0ebae9 100644
--- a/clang/test/Driver/tls-dialect.c
+++ b/clang/test/Driver/tls-dialect.c
@@ -1,3 +1,5 @@
+// RUN: %clang -### --target=loongarch64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
+// RUN: %clang -### --target=loongarch64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-freebsd -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=DESC %s
 // RUN: %clang -### --target=riscv64-linux -mtls-dialect=trad %s 2>&1 | 
FileCheck --check-prefix=NODESC %s
 // RUN: %clang -### --target=riscv64-linux %s 2>&1 | FileCheck 
--check-prefix=NODESC %s
@@ -9,6 +11,8 @@
 // RUN: %clang -### --target=riscv64-android %s 2>&1 | FileCheck 
--check-prefix=DESC %s
 
 /// LTO
+// RUN: %clang -### --target=loongarch64-linux -flto -mtls-dialect=desc %s 
2>&1 | FileCheck --check-prefix=LTO-DESC %s
+// RUN: %clang -### --target=loongarch64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 // RUN: %clang -### --target=riscv64-linux -flto -mtls-dialect=desc %s 2>&1 | 
FileCheck --check-prefix=LTO-DESC %s
 // RUN: %clang -### --target=riscv64-linux -flto %s 2>&1 | FileCheck 
--check-prefix=LTO-NODESC %s
 
@@ -18,6 +22,7 @@
 // RUN: not %clang --target=x86_64-apple-macos -mtls-dialect=desc -flto %s 
2>&1 | FileCheck -check-prefix=UNSUPPORTED-TARGET %s
 
 /// Unsupported argument
+// RUN: not %clang -### --target=loongarch64-linux -mtls-dialect=gnu2 %s 2>&1 
| FileCheck --check-prefix=UNSUPPORTED-ARG %s
 // RUN: not %clang -### --target=riscv64-linux -mtls-dialect=gnu2 %s 2>&1 | 
FileCheck --check-prefix=UNSUPPORTED-ARG %s
 
 // DESC:   "-cc1" {{.*}}"-enable-tlsdesc"

___
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] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-29 Thread Fangrui Song via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/90159
___
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] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-29 Thread Fangrui Song via llvm-branch-commits

MaskRay wrote:

Add a test to clang/test/Driver/tls-dialect.c

https://github.com/llvm/llvm-project/pull/90159
___
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] [polly] release/18.x: [clang-format] Revert breaking stream operators to prev… (PR #89492)

2024-04-29 Thread Owen Pan via llvm-branch-commits

owenca wrote:

@tstellar below is the release notes for clang-format 18.1.5.
- Restores clang-format behavior that always breaks before a stream insertion 
operator (`<<`) when both operands are string literals.
- Fixes clang-format regressions in annotating initialization list braces and 
trailing return type arrow, and breaking after the block comment before a 
function argument.

https://github.com/llvm/llvm-project/pull/89492
___
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] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-29 Thread Pengcheng Wang via llvm-branch-commits

https://github.com/wangpc-pp edited 
https://github.com/llvm/llvm-project/pull/90049
___
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] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-29 Thread Pengcheng Wang via llvm-branch-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/90049


___
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] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-29 Thread Pengcheng Wang via llvm-branch-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/90049


___
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] [flang] [flang][cuda] Lower device/managed/unified allocation to cuda ops (PR #90526)

2024-04-29 Thread Slava Zakharin via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/90526
___
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] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-29 Thread Luke Lau via llvm-branch-commits


@@ -194,15 +194,12 @@ define void @vpmerge_vpload_store( 
%passthru, ptr %p, , i64 } @llvm.riscv.vleff.nxv2i32(, ptr, i64)
 define  @vpmerge_vleff( %passthru, ptr %p, 
 %m, i32 zeroext %vl) {
 ; CHECK-LABEL: vpmerge_vleff:
 ; CHECK:   # %bb.0:
-; CHECK-NEXT:vsetvli zero, a1, e32, m1, ta, ma
-; CHECK-NEXT:vle32ff.v v9, (a0)
-; CHECK-NEXT:vsetvli zero, a1, e32, m1, tu, ma
-; CHECK-NEXT:vmerge.vvm v8, v8, v9, v0
+; CHECK-NEXT:vsetvli zero, a1, e32, m1, tu, mu
+; CHECK-NEXT:vle32ff.v v8, (a0), v0.t

lukel97 wrote:

Looks correct to me.

https://github.com/llvm/llvm-project/pull/90049
___
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] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-29 Thread Luke Lau via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/90049
___
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] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-29 Thread Luke Lau via llvm-branch-commits

https://github.com/lukel97 edited 
https://github.com/llvm/llvm-project/pull/90049
___
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] [flang] [flang][cuda] Lower device/managed/unified allocation to cuda ops (PR #90526)

2024-04-29 Thread Valentin Clement バレンタイン クレメン via llvm-branch-commits

clementval wrote:

> Thank you, Valentin!
> 
> Is it expected that we can have a mix of `fir.alloca` and `fir.cuda_alloc` 
> operations in the device routines (e.g. I suppose 
> `fir::FirOpBuilder::createTemporaryAlloc` can generate `fir.alloca` for a 
> temporary location in device code)? It is not necessarily an issue, I just 
> want to understand whether we will have to handle both operations in the 
> device code.

createTemporaryAlloc will also need to be modified to issue 
cuda_alloc/cuda_free. I'm still evaluating the extend of the change. fir.alloca 
are fine in device code as long as they are not device, managed or unified as 
we can support them with the address space. Note that creating managed or 
unified variabled in device subprogram is not recommended. 

https://github.com/llvm/llvm-project/pull/90526
___
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/18.x: [X86] Enable EVEX512 when host CPU has AVX512 (#90479) (PR #90545)

2024-04-29 Thread via llvm-branch-commits

llvmbot wrote:

@topperc What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/90545
___
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/18.x: [X86] Enable EVEX512 when host CPU has AVX512 (#90479) (PR #90545)

2024-04-29 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/90545
___
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/18.x: [X86] Enable EVEX512 when host CPU has AVX512 (#90479) (PR #90545)

2024-04-29 Thread via llvm-branch-commits

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

Backport b3291793f11924a3b62601aabebebdcfbb12a9a1

Requested by: @nikic

>From 8bb3e9de5f41247c3d9d88f956eb76eb39d136e0 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Tue, 30 Apr 2024 10:09:41 +0800
Subject: [PATCH] [X86] Enable EVEX512 when host CPU has AVX512 (#90479)

This is used when -march=native run on an unknown CPU to old version of
LLVM.

(cherry picked from commit b3291793f11924a3b62601aabebebdcfbb12a9a1)
---
 llvm/lib/TargetParser/Host.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 4466d50458e198..1adef15771fa17 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1266,8 +1266,10 @@ static void getAvailableFeatures(unsigned ECX, unsigned 
EDX, unsigned MaxLeaf,
 setFeature(X86::FEATURE_AVX2);
   if (HasLeaf7 && ((EBX >> 8) & 1))
 setFeature(X86::FEATURE_BMI2);
-  if (HasLeaf7 && ((EBX >> 16) & 1) && HasAVX512Save)
+  if (HasLeaf7 && ((EBX >> 16) & 1) && HasAVX512Save) {
 setFeature(X86::FEATURE_AVX512F);
+setFeature(X86::FEATURE_EVEX512);
+  }
   if (HasLeaf7 && ((EBX >> 17) & 1) && HasAVX512Save)
 setFeature(X86::FEATURE_AVX512DQ);
   if (HasLeaf7 && ((EBX >> 19) & 1))
@@ -1772,6 +1774,7 @@ bool sys::getHostCPUFeatures(StringMap &Features) {
   Features["rtm"]= HasLeaf7 && ((EBX >> 11) & 1);
   // AVX512 is only supported if the OS supports the context save for it.
   Features["avx512f"]= HasLeaf7 && ((EBX >> 16) & 1) && HasAVX512Save;
+  Features["evex512"]= Features["avx512f"];
   Features["avx512dq"]   = HasLeaf7 && ((EBX >> 17) & 1) && HasAVX512Save;
   Features["rdseed"] = HasLeaf7 && ((EBX >> 18) & 1);
   Features["adx"]= HasLeaf7 && ((EBX >> 19) & 1);

___
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] release/18.x [X86_64] fix SSE type error in vaarg (PR #86698)

2024-04-29 Thread Nikita Popov via llvm-branch-commits

nikic wrote:

Closing this as rejected per previous comments.

https://github.com/llvm/llvm-project/pull/86698
___
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] release/18.x [X86_64] fix SSE type error in vaarg (PR #86698)

2024-04-29 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic closed https://github.com/llvm/llvm-project/pull/86698
___
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/18.x: [TableGen] Fix ReplaceRegAction RTTI Kind (PR #89790)

2024-04-29 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic closed https://github.com/llvm/llvm-project/pull/89790
___
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/18.x: [TableGen] Fix ReplaceRegAction RTTI Kind (PR #89790)

2024-04-29 Thread Nikita Popov via llvm-branch-commits

nikic wrote:

@AtariDreams Please, can you stop submitting random backport requests for 
changes that you have no involvement with, and where nobody else expressed a 
desire for a backport?

https://github.com/llvm/llvm-project/pull/89790
___
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] release/18.x: Reland "[clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (#89031)" (PR #90544)

2024-04-29 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport a3f07d36cbc9e3a0d004609d140474c1d8a25bb6

Requested by: @nikic

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


2 Files Affected:

- (modified) clang/lib/Interpreter/IncrementalParser.cpp (+19-5) 
- (modified) clang/lib/Interpreter/IncrementalParser.h (+5) 


``diff
diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 370bcbfee8b014..f5f32b9f3924ae 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -209,6 +209,10 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
   if (Err)
 return;
   CI->ExecuteAction(*Act);
+
+  if (getCodeGen())
+CachedInCodeGenModule = GenModule();
+
   std::unique_ptr IncrConsumer =
   std::make_unique(Interp, CI->takeASTConsumer());
   CI->setASTConsumer(std::move(IncrConsumer));
@@ -224,11 +228,8 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
 return; // PTU.takeError();
   }
 
-  if (CodeGenerator *CG = getCodeGen()) {
-std::unique_ptr M(CG->ReleaseModule());
-CG->StartModule("incr_module_" + std::to_string(PTUs.size()),
-M->getContext());
-PTU->TheModule = std::move(M);
+  if (getCodeGen()) {
+PTU->TheModule = GenModule();
 assert(PTU->TheModule && "Failed to create initial PTU");
   }
 }
@@ -364,6 +365,19 @@ IncrementalParser::Parse(llvm::StringRef input) {
 std::unique_ptr IncrementalParser::GenModule() {
   static unsigned ID = 0;
   if (CodeGenerator *CG = getCodeGen()) {
+// Clang's CodeGen is designed to work with a single llvm::Module. In many
+// cases for convenience various CodeGen parts have a reference to the
+// llvm::Module (TheModule or Module) which does not change when a new
+// module is pushed. However, the execution engine wants to take ownership
+// of the module which does not map well to CodeGen's design. To work this
+// around we created an empty module to make CodeGen happy. We should make
+// sure it always stays empty.
+assert((!CachedInCodeGenModule ||
+(CachedInCodeGenModule->empty() &&
+ CachedInCodeGenModule->global_empty() &&
+ CachedInCodeGenModule->alias_empty() &&
+ CachedInCodeGenModule->ifunc_empty())) &&
+   "CodeGen wrote to a readonly module");
 std::unique_ptr M(CG->ReleaseModule());
 CG->StartModule("incr_module_" + std::to_string(ID++), M->getContext());
 return M;
diff --git a/clang/lib/Interpreter/IncrementalParser.h 
b/clang/lib/Interpreter/IncrementalParser.h
index e13b74c7f65948..f63bce50acd3b9 100644
--- a/clang/lib/Interpreter/IncrementalParser.h
+++ b/clang/lib/Interpreter/IncrementalParser.h
@@ -24,6 +24,7 @@
 #include 
 namespace llvm {
 class LLVMContext;
+class Module;
 } // namespace llvm
 
 namespace clang {
@@ -57,6 +58,10 @@ class IncrementalParser {
   /// of code.
   std::list PTUs;
 
+  /// When CodeGen is created the first llvm::Module gets cached in many places
+  /// and we must keep it alive.
+  std::unique_ptr CachedInCodeGenModule;
+
   IncrementalParser();
 
 public:

``




https://github.com/llvm/llvm-project/pull/90544
___
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] release/18.x: Reland "[clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (#89031)" (PR #90544)

2024-04-29 Thread via llvm-branch-commits

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

Backport a3f07d36cbc9e3a0d004609d140474c1d8a25bb6

Requested by: @nikic

>From 7c0adaa78303cd0bccf1789159cc940e725ac700 Mon Sep 17 00:00:00 2001
From: Vassil Vassilev 
Date: Sat, 20 Apr 2024 18:28:38 +
Subject: [PATCH] Reland "[clang-repl] Keep the first llvm::Module empty to
 avoid invalid memory access. (#89031)"

Original commit message: "

Clang's CodeGen is designed to work with a single llvm::Module. In many cases
for convenience various CodeGen parts have a reference to the llvm::Module
(TheModule or Module) which does not change when a new module is pushed.
However, the execution engine wants to take ownership of the module which does
not map well to CodeGen's design. To work this around we clone the module and
pass it down.

With some effort it is possible to teach CodeGen to ask the CodeGenModule for
its current module and that would have an overall positive impact on CodeGen
improving the encapsulation of various parts but that's not resilient to future
regression.

This patch takes a more conservative approach and keeps the first llvm::Module
empty intentionally and does not pass it to the Jit. That's also not bullet
proof because we have to guarantee that CodeGen does not write on the
blueprint. However, we have inserted some assertions to catch accidental
additions to that canary module.

This change will fixes a long-standing invalid memory access reported by
valgrind when we enable the TBAA optimization passes. It also unblock progress
on https://github.com/llvm/llvm-project/pull/84758.
"

This patch reverts adc4f6233df734fbe3793118ecc89d3584e0c90f and removes
the check of `named_metadata_empty` of the first llvm::Module because on darwin
clang inserts some harmless metadata which we can ignore.

(cherry picked from commit a3f07d36cbc9e3a0d004609d140474c1d8a25bb6)
---
 clang/lib/Interpreter/IncrementalParser.cpp | 24 -
 clang/lib/Interpreter/IncrementalParser.h   |  5 +
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 370bcbfee8b014..f5f32b9f3924ae 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -209,6 +209,10 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
   if (Err)
 return;
   CI->ExecuteAction(*Act);
+
+  if (getCodeGen())
+CachedInCodeGenModule = GenModule();
+
   std::unique_ptr IncrConsumer =
   std::make_unique(Interp, CI->takeASTConsumer());
   CI->setASTConsumer(std::move(IncrConsumer));
@@ -224,11 +228,8 @@ IncrementalParser::IncrementalParser(Interpreter &Interp,
 return; // PTU.takeError();
   }
 
-  if (CodeGenerator *CG = getCodeGen()) {
-std::unique_ptr M(CG->ReleaseModule());
-CG->StartModule("incr_module_" + std::to_string(PTUs.size()),
-M->getContext());
-PTU->TheModule = std::move(M);
+  if (getCodeGen()) {
+PTU->TheModule = GenModule();
 assert(PTU->TheModule && "Failed to create initial PTU");
   }
 }
@@ -364,6 +365,19 @@ IncrementalParser::Parse(llvm::StringRef input) {
 std::unique_ptr IncrementalParser::GenModule() {
   static unsigned ID = 0;
   if (CodeGenerator *CG = getCodeGen()) {
+// Clang's CodeGen is designed to work with a single llvm::Module. In many
+// cases for convenience various CodeGen parts have a reference to the
+// llvm::Module (TheModule or Module) which does not change when a new
+// module is pushed. However, the execution engine wants to take ownership
+// of the module which does not map well to CodeGen's design. To work this
+// around we created an empty module to make CodeGen happy. We should make
+// sure it always stays empty.
+assert((!CachedInCodeGenModule ||
+(CachedInCodeGenModule->empty() &&
+ CachedInCodeGenModule->global_empty() &&
+ CachedInCodeGenModule->alias_empty() &&
+ CachedInCodeGenModule->ifunc_empty())) &&
+   "CodeGen wrote to a readonly module");
 std::unique_ptr M(CG->ReleaseModule());
 CG->StartModule("incr_module_" + std::to_string(ID++), M->getContext());
 return M;
diff --git a/clang/lib/Interpreter/IncrementalParser.h 
b/clang/lib/Interpreter/IncrementalParser.h
index e13b74c7f65948..f63bce50acd3b9 100644
--- a/clang/lib/Interpreter/IncrementalParser.h
+++ b/clang/lib/Interpreter/IncrementalParser.h
@@ -24,6 +24,7 @@
 #include 
 namespace llvm {
 class LLVMContext;
+class Module;
 } // namespace llvm
 
 namespace clang {
@@ -57,6 +58,10 @@ class IncrementalParser {
   /// of code.
   std::list PTUs;
 
+  /// When CodeGen is created the first llvm::Module gets cached in many places
+  /// and we must keep it alive.
+  std::unique_ptr CachedInCodeGenModule;
+
   IncrementalParser();
 
 public:

___
ll

[llvm-branch-commits] [clang] release/18.x: Reland "[clang-repl] Keep the first llvm::Module empty to avoid invalid memory access. (#89031)" (PR #90544)

2024-04-29 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/90544
___
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] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-29 Thread via llvm-branch-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/90159


___
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] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-29 Thread via llvm-branch-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/90159


___
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] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-29 Thread via llvm-branch-commits


@@ -737,7 +737,7 @@ bool tools::isTLSDESCEnabled(const ToolChain &TC,
   StringRef V = A->getValue();
   bool SupportedArgument = false, EnableTLSDESC = false;
   bool Unsupported = !Triple.isOSBinFormatELF();
-  if (Triple.isRISCV()) {
+  if (Triple.isRISCV() || Triple.isLoongArch()) {

wangleiat wrote:

Thanks, I will make the modifications.

https://github.com/llvm/llvm-project/pull/90159
___
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] [flang] [flang][cuda] Lower device/managed/unified allocation to cuda ops (PR #90526)

2024-04-29 Thread Slava Zakharin via llvm-branch-commits

vzakhari wrote:

Thank you, Valentin!

Is it expected that we can have a mix of `fir.alloca` and `fir.cuda_alloc` 
operations in the device routines (e.g. I suppose 
`fir::FirOpBuilder::createTemporaryAlloc` can generate `fir.alloca` for a 
temporary location in device code)?  It is not necessarily an issue, I just 
want to understand whether we will have to handle both operations in the device 
code.

https://github.com/llvm/llvm-project/pull/90526
___
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] [clang][CallGraphSection] Add type id metadata to indirect call and targets (PR #87573)

2024-04-29 Thread Paul Kirth via llvm-branch-commits


@@ -6003,6 +6003,11 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, 
const CGCallee &OrigCallee
 }
   }
 
+  // Set type identifier metadata of indirect calls for call graph section.
+  if (CGM.getCodeGenOpts().CallGraphSection && CallOrInvoke &&
+  CallOrInvoke->isIndirectCall())

ilovepi wrote:

Is `CallOrInvoke` in scope? it appears to be defined in the block above. If its 
shadowing, maybe we want to change that or make sure we don't want the shadowed 
value (e.g. the now out of scope def from line 5990.

https://github.com/llvm/llvm-project/pull/87573
___
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] [clang][CallGraphSection] Add type id metadata to indirect call and targets (PR #87573)

2024-04-29 Thread Paul Kirth via llvm-branch-commits


@@ -5687,6 +5688,39 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   AllocAlignAttrEmitter AllocAlignAttrEmitter(*this, TargetDecl, CallArgs);
   Attrs = AllocAlignAttrEmitter.TryEmitAsCallSiteAttribute(Attrs);
 
+  if (CGM.getCodeGenOpts().CallGraphSection) {
+// FIXME: create operand bundle only for indirect calls, not for all

ilovepi wrote:

Is this something you're planning to address in future patches? Or is this a 
limitation?

https://github.com/llvm/llvm-project/pull/87573
___
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] [clang][CallGraphSection] Add type id metadata to indirect call and targets (PR #87573)

2024-04-29 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi requested changes to this pull request.

Can you split out the LLVM parts from the clang parts? The LLVM bits should 
land first, and then clang can make use of them in a later PR. This will also 
simplify review, since we can focus on the LLVM vs. Clang implementations in 
isolation.

https://github.com/llvm/llvm-project/pull/87573
___
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] [clang][CallGraphSection] Add type id metadata to indirect call and targets (PR #87573)

2024-04-29 Thread Paul Kirth via llvm-branch-commits


@@ -5687,6 +5688,39 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   AllocAlignAttrEmitter AllocAlignAttrEmitter(*this, TargetDecl, CallArgs);
   Attrs = AllocAlignAttrEmitter.TryEmitAsCallSiteAttribute(Attrs);
 
+  if (CGM.getCodeGenOpts().CallGraphSection) {
+// FIXME: create operand bundle only for indirect calls, not for all
+
+assert((TargetDecl && TargetDecl->getFunctionType() ||
+Callee.getAbstractInfo().getCalleeFunctionProtoType()) &&
+   "cannot find callsite type");
+
+QualType CST;
+if (TargetDecl && TargetDecl->getFunctionType())
+  CST = QualType(TargetDecl->getFunctionType(), 0);
+else if (const auto *FPT =
+ Callee.getAbstractInfo().getCalleeFunctionProtoType())
+  CST = QualType(FPT, 0);
+
+if (!CST.isNull()) {
+  auto *TypeIdMD = CGM.CreateMetadataIdentifierGeneralized(CST);
+  auto *TypeIdMDVal =
+  llvm::MetadataAsValue::get(getLLVMContext(), TypeIdMD);
+  BundleList.emplace_back("type", TypeIdMDVal);
+}
+
+// Set type identifier metadata of indirect calls for call graph section.
+if (callOrInvoke && *callOrInvoke && (*callOrInvoke)->isIndirectCall()) {
+  if (const FunctionDecl *FD = dyn_cast_or_null(TargetDecl)) 
{
+// Type id metadata is set only for C/C++ contexts.
+if (isa(FD) || isa(FD) ||
+isa(FD)) {

ilovepi wrote:

I know this is a one off set of checks, but maybe it would be easier to follow 
if it were a helper?

https://github.com/llvm/llvm-project/pull/87573
___
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] [clang][CallGraphSection] Add type id metadata to indirect call and targets (PR #87573)

2024-04-29 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi edited 
https://github.com/llvm/llvm-project/pull/87573
___
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] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-29 Thread Craig Topper via llvm-branch-commits

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

LGTM

https://github.com/llvm/llvm-project/pull/90049
___
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] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-29 Thread Craig Topper via llvm-branch-commits


@@ -194,15 +194,12 @@ define void @vpmerge_vpload_store( 
%passthru, ptr %p, , i64 } @llvm.riscv.vleff.nxv2i32(, ptr, i64)
 define  @vpmerge_vleff( %passthru, ptr %p, 
 %m, i32 zeroext %vl) {
 ; CHECK-LABEL: vpmerge_vleff:
 ; CHECK:   # %bb.0:
-; CHECK-NEXT:vsetvli zero, a1, e32, m1, ta, ma
-; CHECK-NEXT:vle32ff.v v9, (a0)
-; CHECK-NEXT:vsetvli zero, a1, e32, m1, tu, ma
-; CHECK-NEXT:vmerge.vvm v8, v8, v9, v0
+; CHECK-NEXT:vsetvli zero, a1, e32, m1, tu, mu
+; CHECK-NEXT:vle32ff.v v8, (a0), v0.t

topperc wrote:

I'm trying to decide if this is correct. It's certainly a weird test case. You 
would normally want the vp.merge to use vl produced by vleff.

If the VL gets trimmed by the vleff, the elements between the input VL and the 
trimmed VL are undefined if the mask bit for those elements are non-zero. The 
spec allows hardware to write the active elements past the trimmed VL to any 
value.

I think we're ok here. If vleff trims any elements they would be undefined in 
`%b`. The vp.merge would propagate them if the mask bit is non-zero. If the 
mask is 0 the vp.merge would replace them with passthru. That seems to be what 
the combined vp.merge would do.

https://github.com/llvm/llvm-project/pull/90049
___
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] [GSYM] Include end_sequence debug_line rows in Dwarf transform (PR #90535)

2024-04-29 Thread Andres Villegas via llvm-branch-commits

avillega wrote:

I think I can accomplish the same behaviour exposed in 
https://github.com/llvm/llvm-project/pull/89703 which requires a change to the 
DWARF apis without actually changing them. 


https://github.com/llvm/llvm-project/pull/90535
___
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] [GSYM] Include end_sequence debug_line rows in Dwarf transform (PR #90535)

2024-04-29 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-debuginfo

Author: Andres Villegas (avillega)


Changes

Work around for #46494.
This change adds debug_line end_sequence rows when converting
the function line tables. By including the end_sequence
it is possible to handle some edge cases like icf optimizations.


---

Patch is 23.47 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/90535.diff


2 Files Affected:

- (modified) llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp (+21-12) 
- (added) llvm/test/tools/llvm-gsymutil/X86/elf-dwarf-icf.yaml (+564) 


``diff
diff --git a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp 
b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
index ff6b560d11726b..d12dce510e663e 100644
--- a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
+++ b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
@@ -321,7 +321,10 @@ static void convertFunctionLineTable(OutputAggregator 
&Out, CUInfo &CUI,
   StartAddress, object::SectionedAddress::UndefSection};
 
 
-  if (!CUI.LineTable->lookupAddressRange(SecAddress, RangeSize, RowVector)) {
+  // end_sequence markers can be located at RangeSize position,
+  // lookupAddressRange search up to RangeSize not inclusive, to include
+  // end_sequence markers it is necessary to lookup until RangeSize+1
+  if (!CUI.LineTable->lookupAddressRange(SecAddress, RangeSize + 1, 
RowVector)) {
 // If we have a DW_TAG_subprogram but no line entries, fall back to using
 // the DW_AT_decl_file an d DW_AT_decl_line if we have both attributes.
 std::string FilePath = Die.getDeclFile(
@@ -354,6 +357,18 @@ static void convertFunctionLineTable(OutputAggregator 
&Out, CUInfo &CUI,
   for (uint32_t RowIndex : RowVector) {
 // Take file number and line/column from the row.
 const DWARFDebugLine::Row &Row = CUI.LineTable->Rows[RowIndex];
+
+// TODO(avillega): With this conditional, functions folded by `icf`
+// optimizations will only include 1 of all the folded functions. There is
+// not a clear path forward to have the information of all folded functions
+// in gsym.
+if (Row.EndSequence) {
+  // End sequence markers are included for the last address
+  // in a function or the last contiguos address in a sequence.
+  break;
+}
+
+
 std::optional OptFileIdx =
 CUI.DWARFToGSYMFileIndex(Gsym, Row.File);
 if (!OptFileIdx) {
@@ -411,7 +426,7 @@ static void convertFunctionLineTable(OutputAggregator &Out, 
CUInfo &CUI,
   else
 Out.Report("Non-monotonically increasing addresses",
[&](raw_ostream &OS) {
- OS << "error: line table has addresses that do not "
+ OS << "warning: line table has addresses that do not "
 << "monotonically increase:\n";
  for (uint32_t RowIndex2 : RowVector)
CUI.LineTable->Rows[RowIndex2].dump(OS);
@@ -424,19 +439,13 @@ static void convertFunctionLineTable(OutputAggregator 
&Out, CUInfo &CUI,
 auto LastLE = FI.OptLineTable->last();
 if (LastLE && LastLE->File == FileIdx && LastLE->Line == Row.Line)
 continue;
+
 // Only push a row if it isn't an end sequence. End sequence markers are
 // included for the last address in a function or the last contiguous
 // address in a sequence.
-if (Row.EndSequence) {
-  // End sequence means that the next line entry could have a lower address
-  // that the previous entries. So we clear the previous row so we don't
-  // trigger the line table error about address that do not monotonically
-  // increase.
-  PrevRow = DWARFDebugLine::Row();
-} else {
-  FI.OptLineTable->push(LE);
-  PrevRow = Row;
-}
+FI.OptLineTable->push(LE);
+PrevRow = Row;
+
   }
   // If not line table rows were added, clear the line table so we don't encode
   // on in the GSYM file.
diff --git a/llvm/test/tools/llvm-gsymutil/X86/elf-dwarf-icf.yaml 
b/llvm/test/tools/llvm-gsymutil/X86/elf-dwarf-icf.yaml
new file mode 100644
index 00..0e1e507179057b
--- /dev/null
+++ b/llvm/test/tools/llvm-gsymutil/X86/elf-dwarf-icf.yaml
@@ -0,0 +1,564 @@
+## Test loading an ELF file with DWARF with icf (identical code folding) 
+## optimizations.
+## First we make the ELF file from yaml,
+## then we convert the ELF file to GSYM, then we do lookups on the newly
+## created GSYM, and finally we dump the entire GSYM.
+##
+## The elf file corresponds to this c program:
+## int f() {
+##   return 1;
+## }
+## 
+## int g() {
+##   return 1;
+## }
+## 
+## int main() {
+##   f();
+##   g();
+##   return 0;
+## }
+
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-gsymutil --convert %t --out-file=%t.gsym 2>&1 | FileCheck %s 
--check-prefix=CONVERT --dump-input=always
+
+# CONVERT-NOT: warning: line table has addresses that do not monotonically 
increase
+# CONVERT: Input file: {{.*\.yaml\.tmp}}
+# CONVERT: Output file (x86_64): {{.*\.yaml\.tmp\.gsym}}
+#

[llvm-branch-commits] [GSYM] Include end_sequence debug_line rows in Dwarf transform (PR #90535)

2024-04-29 Thread Andres Villegas via llvm-branch-commits

https://github.com/avillega created 
https://github.com/llvm/llvm-project/pull/90535

Work around for #46494.
This change adds debug_line end_sequence rows when converting
the function line tables. By including the end_sequence
it is possible to handle some edge cases like icf optimizations.



___
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] [BOLT][NFCI] Use heuristic for matching split global functions (PR #90429)

2024-04-29 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/90429
___
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] [BOLT][NFCI] Use heuristic for matching split global functions (PR #90429)

2024-04-29 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/90429
___
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] [BOLT][NFCI] Use heuristic for matching split global functions (PR #90429)

2024-04-29 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/90429


___
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] [BOLT][NFCI] Use heuristic for matching split global functions (PR #90429)

2024-04-29 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/90429


___
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] [BOLT] Use heuristic for matching split local functions (PR #90424)

2024-04-29 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/90424

>From b9a8ff53a491f126fb0dcf8cc371ed7a053e859b Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 29 Apr 2024 12:48:24 -0700
Subject: [PATCH 1/4] Revert cdsplit-symbol-names.s

---
 bolt/test/X86/cdsplit-symbol-names.s | 24 
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/bolt/test/X86/cdsplit-symbol-names.s 
b/bolt/test/X86/cdsplit-symbol-names.s
index 0d9149f49db908..e53863e22246d6 100644
--- a/bolt/test/X86/cdsplit-symbol-names.s
+++ b/bolt/test/X86/cdsplit-symbol-names.s
@@ -2,14 +2,12 @@
 # Warm section should have name .text.warm and warm function fragments should
 # have symbol names ending in warm.
 
-# RUN: split-file %s %t
-# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %t/main.s -o %t.o
-# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %t/chain.s -o 
%t.chain.o
+# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.o
 # RUN: link_fdata %s %t.o %t.fdata
 # RUN: llvm-strip --strip-unneeded %t.o
-# RUN: %clang %cflags %t.o %t.chain.o -o %t.exe -Wl,-q
+# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
 # RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-strategy=cdsplit \
-# RUN:   --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp --enable-bat
+# RUN: --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp
 # RUN: llvm-objdump --syms %t.bolt | FileCheck %s 
--check-prefix=CHECK-SYMS-WARM
 
 # CHECK-SYMS-WARM:  l df *ABS*  bolt-pseudo.o
@@ -18,22 +16,8 @@
 # CHECK-SYMS-WARM: .text.cold
 # CHECK-SYMS-WARM-SAME: dummy.cold
 
-# RUN: link_fdata %s %t.bolt %t.preagg PREAGG
-# PREAGG: B X:0 #chain.warm# 1 0
-# RUN: perf2bolt %t.bolt -p %t.preagg --pa -o %t.bat.fdata -w %t.bat.yaml -v=1 
\
-# RUN:   | FileCheck %s --check-prefix=CHECK-REGISTER
-
-# CHECK-REGISTER: BOLT-INFO: marking chain.warm/1(*2) as a fragment of 
chain/2(*2)
-
-#--- chain.s
-.text
-.type   chain, @function
-chain:
-ret
-.size   chain, .-chain
-
-#--- main.s
 .text
+.globl  chain
 .type   chain, @function
 chain:
 pushq   %rbp

>From 7c92aca6a0cba71bfde9eb2127575d93e210d346 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 29 Apr 2024 12:48:39 -0700
Subject: [PATCH 2/4] Add register-fragments-bolt-symbols.s

---
 .../X86/register-fragments-bolt-symbols.s | 32 +++
 1 file changed, 32 insertions(+)
 create mode 100644 bolt/test/X86/register-fragments-bolt-symbols.s

diff --git a/bolt/test/X86/register-fragments-bolt-symbols.s 
b/bolt/test/X86/register-fragments-bolt-symbols.s
new file mode 100644
index 00..fa9b70e0b2d891
--- /dev/null
+++ b/bolt/test/X86/register-fragments-bolt-symbols.s
@@ -0,0 +1,32 @@
+# Test the heuristics for matching BOLT-added split functions.
+
+# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown 
%S/cdsplit-symbol-names.s -o %t.main.o
+# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.chain.o
+# RUN: link_fdata %S/cdsplit-symbol-names.s %t.main.o %t.fdata
+# RUN: sed -i 's|chain|chain/2|g' %t.fdata
+# RUN: llvm-strip --strip-unneeded %t.main.o
+# RUN: llvm-objcopy --localize-symbol=chain %t.main.o
+# RUN: %clang %cflags %t.chain.o %t.main.o -o %t.exe -Wl,-q
+# RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-strategy=randomN \
+# RUN:   --reorder-blocks=ext-tsp --enable-bat --bolt-seed=7 --data=%t.fdata
+# RUN: llvm-objdump --syms %t.bolt | FileCheck %s --check-prefix=CHECK-SYMS
+
+# RUN: link_fdata %s %t.bolt %t.preagg PREAGG
+# PREAGG: B X:0 #chain.cold.0# 1 0
+# RUN: perf2bolt %t.bolt -p %t.preagg --pa -o %t.bat.fdata -w %t.bat.yaml -v=1 
\
+# RUN:   | FileCheck %s --check-prefix=CHECK-REGISTER
+
+# CHECK-SYMS: l df *ABS*  [[#]] chain.s
+# CHECK-SYMS: l  F .bolt.org.text [[#]] chain
+# CHECK-SYMS: l  F .text.cold [[#]] chain.cold.0
+# CHECK-SYMS: l  F .text  [[#]] chain
+# CHECK-SYMS: l df *ABS*  [[#]] bolt-pseudo.o
+
+# CHECK-REGISTER: BOLT-INFO: marking chain.cold.0/1(*2) as a fragment of 
chain/2(*2)
+
+.file "chain.s"
+.text
+.type   chain, @function
+chain:
+ret
+.size   chain, .-chain

>From a94e14566de73e4a54a28086c95d742a1f09e7b4 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 29 Apr 2024 12:50:07 -0700
Subject: [PATCH 3/4] Fix a mistake in NameOrError

---
 bolt/lib/Rewrite/RewriteInstance.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp 
b/bolt/lib/Rewrite/RewriteInstance.cpp
index 8eb2e5a9d9120a..5e7bcd06df82c4 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1515,7 +1515,7 @@ void RewriteInstance::registerFragments() {
 // symbol.
 for (ELFSymbolRef NextSymbol = Symbol; NextSymbol < StopSymbol;
  NextSymbol.moveNext()) {
-  Expected NameOrError = Sy

[llvm-branch-commits] [llvm] [BOLT] Use heuristic for matching split local functions (PR #90424)

2024-04-29 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/90424

>From b9a8ff53a491f126fb0dcf8cc371ed7a053e859b Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 29 Apr 2024 12:48:24 -0700
Subject: [PATCH 1/4] Revert cdsplit-symbol-names.s

---
 bolt/test/X86/cdsplit-symbol-names.s | 24 
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/bolt/test/X86/cdsplit-symbol-names.s 
b/bolt/test/X86/cdsplit-symbol-names.s
index 0d9149f49db908..e53863e22246d6 100644
--- a/bolt/test/X86/cdsplit-symbol-names.s
+++ b/bolt/test/X86/cdsplit-symbol-names.s
@@ -2,14 +2,12 @@
 # Warm section should have name .text.warm and warm function fragments should
 # have symbol names ending in warm.
 
-# RUN: split-file %s %t
-# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %t/main.s -o %t.o
-# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %t/chain.s -o 
%t.chain.o
+# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.o
 # RUN: link_fdata %s %t.o %t.fdata
 # RUN: llvm-strip --strip-unneeded %t.o
-# RUN: %clang %cflags %t.o %t.chain.o -o %t.exe -Wl,-q
+# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
 # RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-strategy=cdsplit \
-# RUN:   --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp --enable-bat
+# RUN: --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp
 # RUN: llvm-objdump --syms %t.bolt | FileCheck %s 
--check-prefix=CHECK-SYMS-WARM
 
 # CHECK-SYMS-WARM:  l df *ABS*  bolt-pseudo.o
@@ -18,22 +16,8 @@
 # CHECK-SYMS-WARM: .text.cold
 # CHECK-SYMS-WARM-SAME: dummy.cold
 
-# RUN: link_fdata %s %t.bolt %t.preagg PREAGG
-# PREAGG: B X:0 #chain.warm# 1 0
-# RUN: perf2bolt %t.bolt -p %t.preagg --pa -o %t.bat.fdata -w %t.bat.yaml -v=1 
\
-# RUN:   | FileCheck %s --check-prefix=CHECK-REGISTER
-
-# CHECK-REGISTER: BOLT-INFO: marking chain.warm/1(*2) as a fragment of 
chain/2(*2)
-
-#--- chain.s
-.text
-.type   chain, @function
-chain:
-ret
-.size   chain, .-chain
-
-#--- main.s
 .text
+.globl  chain
 .type   chain, @function
 chain:
 pushq   %rbp

>From 7c92aca6a0cba71bfde9eb2127575d93e210d346 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 29 Apr 2024 12:48:39 -0700
Subject: [PATCH 2/4] Add register-fragments-bolt-symbols.s

---
 .../X86/register-fragments-bolt-symbols.s | 32 +++
 1 file changed, 32 insertions(+)
 create mode 100644 bolt/test/X86/register-fragments-bolt-symbols.s

diff --git a/bolt/test/X86/register-fragments-bolt-symbols.s 
b/bolt/test/X86/register-fragments-bolt-symbols.s
new file mode 100644
index 00..fa9b70e0b2d891
--- /dev/null
+++ b/bolt/test/X86/register-fragments-bolt-symbols.s
@@ -0,0 +1,32 @@
+# Test the heuristics for matching BOLT-added split functions.
+
+# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown 
%S/cdsplit-symbol-names.s -o %t.main.o
+# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.chain.o
+# RUN: link_fdata %S/cdsplit-symbol-names.s %t.main.o %t.fdata
+# RUN: sed -i 's|chain|chain/2|g' %t.fdata
+# RUN: llvm-strip --strip-unneeded %t.main.o
+# RUN: llvm-objcopy --localize-symbol=chain %t.main.o
+# RUN: %clang %cflags %t.chain.o %t.main.o -o %t.exe -Wl,-q
+# RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-strategy=randomN \
+# RUN:   --reorder-blocks=ext-tsp --enable-bat --bolt-seed=7 --data=%t.fdata
+# RUN: llvm-objdump --syms %t.bolt | FileCheck %s --check-prefix=CHECK-SYMS
+
+# RUN: link_fdata %s %t.bolt %t.preagg PREAGG
+# PREAGG: B X:0 #chain.cold.0# 1 0
+# RUN: perf2bolt %t.bolt -p %t.preagg --pa -o %t.bat.fdata -w %t.bat.yaml -v=1 
\
+# RUN:   | FileCheck %s --check-prefix=CHECK-REGISTER
+
+# CHECK-SYMS: l df *ABS*  [[#]] chain.s
+# CHECK-SYMS: l  F .bolt.org.text [[#]] chain
+# CHECK-SYMS: l  F .text.cold [[#]] chain.cold.0
+# CHECK-SYMS: l  F .text  [[#]] chain
+# CHECK-SYMS: l df *ABS*  [[#]] bolt-pseudo.o
+
+# CHECK-REGISTER: BOLT-INFO: marking chain.cold.0/1(*2) as a fragment of 
chain/2(*2)
+
+.file "chain.s"
+.text
+.type   chain, @function
+chain:
+ret
+.size   chain, .-chain

>From a94e14566de73e4a54a28086c95d742a1f09e7b4 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 29 Apr 2024 12:50:07 -0700
Subject: [PATCH 3/4] Fix a mistake in NameOrError

---
 bolt/lib/Rewrite/RewriteInstance.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp 
b/bolt/lib/Rewrite/RewriteInstance.cpp
index 8eb2e5a9d9120a..5e7bcd06df82c4 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1515,7 +1515,7 @@ void RewriteInstance::registerFragments() {
 // symbol.
 for (ELFSymbolRef NextSymbol = Symbol; NextSymbol < StopSymbol;
  NextSymbol.moveNext()) {
-  Expected NameOrError = Sy

[llvm-branch-commits] [llvm] [BOLT] Use heuristic for matching split local functions (PR #90424)

2024-04-29 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/90424
___
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] [BOLT] Use heuristic for matching split local functions (PR #90424)

2024-04-29 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/90424

>From b9a8ff53a491f126fb0dcf8cc371ed7a053e859b Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 29 Apr 2024 12:48:24 -0700
Subject: [PATCH 1/4] Revert cdsplit-symbol-names.s

---
 bolt/test/X86/cdsplit-symbol-names.s | 24 
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/bolt/test/X86/cdsplit-symbol-names.s 
b/bolt/test/X86/cdsplit-symbol-names.s
index 0d9149f49db908..e53863e22246d6 100644
--- a/bolt/test/X86/cdsplit-symbol-names.s
+++ b/bolt/test/X86/cdsplit-symbol-names.s
@@ -2,14 +2,12 @@
 # Warm section should have name .text.warm and warm function fragments should
 # have symbol names ending in warm.
 
-# RUN: split-file %s %t
-# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %t/main.s -o %t.o
-# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %t/chain.s -o 
%t.chain.o
+# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.o
 # RUN: link_fdata %s %t.o %t.fdata
 # RUN: llvm-strip --strip-unneeded %t.o
-# RUN: %clang %cflags %t.o %t.chain.o -o %t.exe -Wl,-q
+# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
 # RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-strategy=cdsplit \
-# RUN:   --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp --enable-bat
+# RUN: --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp
 # RUN: llvm-objdump --syms %t.bolt | FileCheck %s 
--check-prefix=CHECK-SYMS-WARM
 
 # CHECK-SYMS-WARM:  l df *ABS*  bolt-pseudo.o
@@ -18,22 +16,8 @@
 # CHECK-SYMS-WARM: .text.cold
 # CHECK-SYMS-WARM-SAME: dummy.cold
 
-# RUN: link_fdata %s %t.bolt %t.preagg PREAGG
-# PREAGG: B X:0 #chain.warm# 1 0
-# RUN: perf2bolt %t.bolt -p %t.preagg --pa -o %t.bat.fdata -w %t.bat.yaml -v=1 
\
-# RUN:   | FileCheck %s --check-prefix=CHECK-REGISTER
-
-# CHECK-REGISTER: BOLT-INFO: marking chain.warm/1(*2) as a fragment of 
chain/2(*2)
-
-#--- chain.s
-.text
-.type   chain, @function
-chain:
-ret
-.size   chain, .-chain
-
-#--- main.s
 .text
+.globl  chain
 .type   chain, @function
 chain:
 pushq   %rbp

>From 7c92aca6a0cba71bfde9eb2127575d93e210d346 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 29 Apr 2024 12:48:39 -0700
Subject: [PATCH 2/4] Add register-fragments-bolt-symbols.s

---
 .../X86/register-fragments-bolt-symbols.s | 32 +++
 1 file changed, 32 insertions(+)
 create mode 100644 bolt/test/X86/register-fragments-bolt-symbols.s

diff --git a/bolt/test/X86/register-fragments-bolt-symbols.s 
b/bolt/test/X86/register-fragments-bolt-symbols.s
new file mode 100644
index 00..fa9b70e0b2d891
--- /dev/null
+++ b/bolt/test/X86/register-fragments-bolt-symbols.s
@@ -0,0 +1,32 @@
+# Test the heuristics for matching BOLT-added split functions.
+
+# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown 
%S/cdsplit-symbol-names.s -o %t.main.o
+# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.chain.o
+# RUN: link_fdata %S/cdsplit-symbol-names.s %t.main.o %t.fdata
+# RUN: sed -i 's|chain|chain/2|g' %t.fdata
+# RUN: llvm-strip --strip-unneeded %t.main.o
+# RUN: llvm-objcopy --localize-symbol=chain %t.main.o
+# RUN: %clang %cflags %t.chain.o %t.main.o -o %t.exe -Wl,-q
+# RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-strategy=randomN \
+# RUN:   --reorder-blocks=ext-tsp --enable-bat --bolt-seed=7 --data=%t.fdata
+# RUN: llvm-objdump --syms %t.bolt | FileCheck %s --check-prefix=CHECK-SYMS
+
+# RUN: link_fdata %s %t.bolt %t.preagg PREAGG
+# PREAGG: B X:0 #chain.cold.0# 1 0
+# RUN: perf2bolt %t.bolt -p %t.preagg --pa -o %t.bat.fdata -w %t.bat.yaml -v=1 
\
+# RUN:   | FileCheck %s --check-prefix=CHECK-REGISTER
+
+# CHECK-SYMS: l df *ABS*  [[#]] chain.s
+# CHECK-SYMS: l  F .bolt.org.text [[#]] chain
+# CHECK-SYMS: l  F .text.cold [[#]] chain.cold.0
+# CHECK-SYMS: l  F .text  [[#]] chain
+# CHECK-SYMS: l df *ABS*  [[#]] bolt-pseudo.o
+
+# CHECK-REGISTER: BOLT-INFO: marking chain.cold.0/1(*2) as a fragment of 
chain/2(*2)
+
+.file "chain.s"
+.text
+.type   chain, @function
+chain:
+ret
+.size   chain, .-chain

>From a94e14566de73e4a54a28086c95d742a1f09e7b4 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Mon, 29 Apr 2024 12:50:07 -0700
Subject: [PATCH 3/4] Fix a mistake in NameOrError

---
 bolt/lib/Rewrite/RewriteInstance.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp 
b/bolt/lib/Rewrite/RewriteInstance.cpp
index 8eb2e5a9d9120a..5e7bcd06df82c4 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1515,7 +1515,7 @@ void RewriteInstance::registerFragments() {
 // symbol.
 for (ELFSymbolRef NextSymbol = Symbol; NextSymbol < StopSymbol;
  NextSymbol.moveNext()) {
-  Expected NameOrError = Sy

[llvm-branch-commits] [llvm] [MTE] add stack frame history buffer (PR #86356)

2024-04-29 Thread Florian Mayer via llvm-branch-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/86356

>From a64c5d63a4df7f59845291ca0d634466713b1ff8 Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Fri, 29 Mar 2024 16:53:52 -0700
Subject: [PATCH 1/3] update

Created using spr 1.3.4
---
 llvm/lib/Target/AArch64/AArch64StackTagging.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp 
b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
index a6e236386d5baa..6538abea832907 100644
--- a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
+++ b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
@@ -489,7 +489,6 @@ Instruction *AArch64StackTagging::insertBaseTaggedPointer(
 
 auto *IntptrTy = IRB.getIntPtrTy(M.getDataLayout());
 Value *SlotPtr = memtag::getAndroidSlotPtr(IRB, StackMteSlot);
-SlotPtr->setName("TLS_SLOT_STACK_MTE");
 auto *ThreadLong = IRB.CreateLoad(IntptrTy, SlotPtr);
 Value *TaggedFP = IRB.CreateOr(
 memtag::getFP(IRB),

>From 8591fb38c7e065862a0814792a368e2983b8b10c Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Mon, 29 Apr 2024 14:45:16 -0700
Subject: [PATCH 2/3] api lvl

Created using spr 1.3.4
---
 llvm/lib/Target/AArch64/AArch64StackTagging.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp 
b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
index 840635315eee04..e38cce94a5cc0b 100644
--- a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
+++ b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
@@ -484,7 +484,7 @@ Instruction *AArch64StackTagging::insertBaseTaggedPointer(
   Base->setName("basetag");
   auto TargetTriple = Triple(M.getTargetTriple());
   if (ClRecordStackHistory == instr && TargetTriple.isAndroid() &&
-  TargetTriple.isAArch64() && !TargetTriple.isAndroidVersionLT(35)) {
+  TargetTriple.isAArch64() && !TargetTriple.isAndroidVersionLT(36)) {
 constexpr int StackMteSlot = -3;
 constexpr uint64_t TagMask = 0xFULL << 56;
 

>From 66fbd757608c44b04d64de3f058ce813b14706fe Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Mon, 29 Apr 2024 16:00:09 -0700
Subject: [PATCH 3/3] hidden

Created using spr 1.3.4
---
 llvm/lib/Target/AArch64/AArch64StackTagging.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp 
b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
index e38cce94a5cc0b..43d82a1234f7af 100644
--- a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
+++ b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
@@ -102,7 +102,7 @@ static cl::opt ClRecordStackHistory(
 cl::values(clEnumVal(none, "Do not record stack ring history"),
clEnumVal(instr, "Insert instructions into the prologue for "
 "storing into the stack ring buffer")),
-cl::Hidden, cl::init(instr));
+cl::Hidden, cl::init(none));
 
 static const Align kTagGranuleSize = Align(16);
 

___
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] f341c76 - [Clang] Handle structs with inner structs and no fields (#89126)

2024-04-29 Thread Tom Stellard via llvm-branch-commits

Author: Bill Wendling
Date: 2024-04-29T15:49:15-07:00
New Revision: f341c76b946142366d2b4eabcb1190347be4665b

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

LOG: [Clang] Handle structs with inner structs and no fields (#89126)

A struct that declares an inner struct, but no fields, won't have a
field count. So getting the offset of the inner struct fails. This
happens in both C and C++:

  struct foo {
struct bar {
  int Quantizermatrix[];
};
  };

Here 'struct foo' has no fields.

Closes: https://github.com/llvm/llvm-project/issues/88931

Added: 
clang/test/CodeGen/attr-counted-by-pr88931.c
clang/test/CodeGen/attr-counted-by-pr88931.cpp

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a4f26a6f0eb19b..44ddd2428b10f5 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -823,29 +823,32 @@ const FieldDecl 
*CodeGenFunction::FindFlexibleArrayMemberField(
 ASTContext &Ctx, const RecordDecl *RD, StringRef Name, uint64_t &Offset) {
   const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
   getLangOpts().getStrictFlexArraysLevel();
-  unsigned FieldNo = 0;
-  bool IsUnion = RD->isUnion();
+  uint32_t FieldNo = 0;
 
-  for (const Decl *D : RD->decls()) {
-if (const auto *Field = dyn_cast(D);
-Field && (Name.empty() || Field->getNameAsString() == Name) &&
+  if (RD->isImplicit())
+return nullptr;
+
+  for (const FieldDecl *FD : RD->fields()) {
+if ((Name.empty() || FD->getNameAsString() == Name) &&
 Decl::isFlexibleArrayMemberLike(
-Ctx, Field, Field->getType(), StrictFlexArraysLevel,
+Ctx, FD, FD->getType(), StrictFlexArraysLevel,
 /*IgnoreTemplateOrMacroSubstitution=*/true)) {
   const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
   Offset += Layout.getFieldOffset(FieldNo);
-  return Field;
+  return FD;
 }
 
-if (const auto *Record = dyn_cast(D))
-  if (const FieldDecl *Field =
-  FindFlexibleArrayMemberField(Ctx, Record, Name, Offset)) {
+QualType Ty = FD->getType();
+if (Ty->isRecordType()) {
+  if (const FieldDecl *Field = FindFlexibleArrayMemberField(
+  Ctx, Ty->getAsRecordDecl(), Name, Offset)) {
 const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
 Offset += Layout.getFieldOffset(FieldNo);
 return Field;
   }
+}
 
-if (!IsUnion && isa(D))
+if (!RD->isUnion())
   ++FieldNo;
   }
 

diff  --git a/clang/test/CodeGen/attr-counted-by-pr88931.c 
b/clang/test/CodeGen/attr-counted-by-pr88931.c
new file mode 100644
index 00..520ebd09973284
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-pr88931.c
@@ -0,0 +1,40 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 
-Wno-missing-declarations -emit-llvm -o - %s | FileCheck %s
+
+struct foo {
+  int x,y,z;
+  struct bar {
+int count;
+int array[] __attribute__((counted_by(count)));
+  };
+};
+
+void init(void * __attribute__((pass_dynamic_object_size(0;
+
+// CHECK-LABEL: define dso_local void @test1(
+// CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ARRAY:%.*]] = getelementptr inbounds [[STRUCT_BAR:%.*]], 
ptr [[P]], i64 0, i32 1
+// CHECK-NEXT:tail call void @init(ptr noundef nonnull [[ARRAY]], i64 
noundef -1) #[[ATTR2:[0-9]+]]
+// CHECK-NEXT:ret void
+//
+void test1(struct bar *p) {
+  init(p->array);
+}
+
+struct mux {
+  int count;
+  int array[] __attribute__((counted_by(count)));
+};
+
+struct bux { struct mux x; };
+
+// CHECK-LABEL: define dso_local void @test2(
+// CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @init(ptr noundef [[P]], i64 noundef -1) 
#[[ATTR2]]
+// CHECK-NEXT:ret void
+//
+void test2(struct bux *p) {
+  init(p);
+}

diff  --git a/clang/test/CodeGen/attr-counted-by-pr88931.cpp 
b/clang/test/CodeGen/attr-counted-by-pr88931.cpp
new file mode 100644
index 00..2a8cc1d07e50d9
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-pr88931.cpp
@@ -0,0 +1,21 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -Wall -emit-llvm -o - 
%s | FileCheck %s
+
+struct foo {
+  struct bar {
+int array[];
+bar();
+  };
+};
+
+void init(void * __attribute__((pass_dynamic_object_size(0;
+
+// CHECK-LABEL: define dso_local void @_ZN3foo3barC1Ev(
+// CHE

[llvm-branch-commits] [clang] [Clang] Handle structs with inner structs and no fields (#89126) (PR #90133)

2024-04-29 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/90133
___
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] [Clang] Handle structs with inner structs and no fields (#89126) (PR #90133)

2024-04-29 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/90133

>From f341c76b946142366d2b4eabcb1190347be4665b Mon Sep 17 00:00:00 2001
From: Bill Wendling <5993918+bwendl...@users.noreply.github.com>
Date: Fri, 19 Apr 2024 12:48:33 -0700
Subject: [PATCH] [Clang] Handle structs with inner structs and no fields
 (#89126)

A struct that declares an inner struct, but no fields, won't have a
field count. So getting the offset of the inner struct fails. This
happens in both C and C++:

  struct foo {
struct bar {
  int Quantizermatrix[];
};
  };

Here 'struct foo' has no fields.

Closes: https://github.com/llvm/llvm-project/issues/88931
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 25 +++-
 clang/test/CodeGen/attr-counted-by-pr88931.c  | 40 +++
 .../test/CodeGen/attr-counted-by-pr88931.cpp  | 21 ++
 3 files changed, 75 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-counted-by-pr88931.c
 create mode 100644 clang/test/CodeGen/attr-counted-by-pr88931.cpp

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a4f26a6f0eb19b..44ddd2428b10f5 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -823,29 +823,32 @@ const FieldDecl 
*CodeGenFunction::FindFlexibleArrayMemberField(
 ASTContext &Ctx, const RecordDecl *RD, StringRef Name, uint64_t &Offset) {
   const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
   getLangOpts().getStrictFlexArraysLevel();
-  unsigned FieldNo = 0;
-  bool IsUnion = RD->isUnion();
+  uint32_t FieldNo = 0;
 
-  for (const Decl *D : RD->decls()) {
-if (const auto *Field = dyn_cast(D);
-Field && (Name.empty() || Field->getNameAsString() == Name) &&
+  if (RD->isImplicit())
+return nullptr;
+
+  for (const FieldDecl *FD : RD->fields()) {
+if ((Name.empty() || FD->getNameAsString() == Name) &&
 Decl::isFlexibleArrayMemberLike(
-Ctx, Field, Field->getType(), StrictFlexArraysLevel,
+Ctx, FD, FD->getType(), StrictFlexArraysLevel,
 /*IgnoreTemplateOrMacroSubstitution=*/true)) {
   const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
   Offset += Layout.getFieldOffset(FieldNo);
-  return Field;
+  return FD;
 }
 
-if (const auto *Record = dyn_cast(D))
-  if (const FieldDecl *Field =
-  FindFlexibleArrayMemberField(Ctx, Record, Name, Offset)) {
+QualType Ty = FD->getType();
+if (Ty->isRecordType()) {
+  if (const FieldDecl *Field = FindFlexibleArrayMemberField(
+  Ctx, Ty->getAsRecordDecl(), Name, Offset)) {
 const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
 Offset += Layout.getFieldOffset(FieldNo);
 return Field;
   }
+}
 
-if (!IsUnion && isa(D))
+if (!RD->isUnion())
   ++FieldNo;
   }
 
diff --git a/clang/test/CodeGen/attr-counted-by-pr88931.c 
b/clang/test/CodeGen/attr-counted-by-pr88931.c
new file mode 100644
index 00..520ebd09973284
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-pr88931.c
@@ -0,0 +1,40 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 
-Wno-missing-declarations -emit-llvm -o - %s | FileCheck %s
+
+struct foo {
+  int x,y,z;
+  struct bar {
+int count;
+int array[] __attribute__((counted_by(count)));
+  };
+};
+
+void init(void * __attribute__((pass_dynamic_object_size(0;
+
+// CHECK-LABEL: define dso_local void @test1(
+// CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ARRAY:%.*]] = getelementptr inbounds [[STRUCT_BAR:%.*]], 
ptr [[P]], i64 0, i32 1
+// CHECK-NEXT:tail call void @init(ptr noundef nonnull [[ARRAY]], i64 
noundef -1) #[[ATTR2:[0-9]+]]
+// CHECK-NEXT:ret void
+//
+void test1(struct bar *p) {
+  init(p->array);
+}
+
+struct mux {
+  int count;
+  int array[] __attribute__((counted_by(count)));
+};
+
+struct bux { struct mux x; };
+
+// CHECK-LABEL: define dso_local void @test2(
+// CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @init(ptr noundef [[P]], i64 noundef -1) 
#[[ATTR2]]
+// CHECK-NEXT:ret void
+//
+void test2(struct bux *p) {
+  init(p);
+}
diff --git a/clang/test/CodeGen/attr-counted-by-pr88931.cpp 
b/clang/test/CodeGen/attr-counted-by-pr88931.cpp
new file mode 100644
index 00..2a8cc1d07e50d9
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-pr88931.cpp
@@ -0,0 +1,21 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -Wall -emit-llvm -o - 
%s | FileCheck %s
+
+struct foo {
+  struct bar {
+int array[];
+bar();
+  };
+};
+
+void init(void * __attribut

[llvm-branch-commits] [llvm] abf6b13 - [IRCE] Skip icmp ptr in `InductiveRangeCheck::parseRangeCheckICmp` (#89967)

2024-04-29 Thread Tom Stellard via llvm-branch-commits

Author: Yingwei Zheng
Date: 2024-04-29T15:47:28-07:00
New Revision: abf6b13085fbffe6d0384420d9bf562e2f1698c8

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

LOG: [IRCE] Skip icmp ptr in `InductiveRangeCheck::parseRangeCheckICmp` (#89967)

Fixes https://github.com/llvm/llvm-project/issues/89959.

(cherry picked from commit 22da5a6e34ed6146752b24d9156a678b50fddaef)

Added: 
llvm/test/Transforms/IRCE/pr89959.ll

Modified: 
llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp

Removed: 




diff  --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp 
b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
index 9df28747570c4d..104e8ceb796700 100644
--- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -279,6 +279,9 @@ bool InductiveRangeCheck::parseRangeCheckICmp(Loop *L, 
ICmpInst *ICI,
   Value *LHS = ICI->getOperand(0);
   Value *RHS = ICI->getOperand(1);
 
+  if (!LHS->getType()->isIntegerTy())
+return false;
+
   // Canonicalize to the `Index Pred Invariant` comparison
   if (IsLoopInvariant(LHS)) {
 std::swap(LHS, RHS);

diff  --git a/llvm/test/Transforms/IRCE/pr89959.ll 
b/llvm/test/Transforms/IRCE/pr89959.ll
new file mode 100644
index 00..dc7c0dfbc57a97
--- /dev/null
+++ b/llvm/test/Transforms/IRCE/pr89959.ll
@@ -0,0 +1,33 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 4
+; RUN: opt -passes=irce -S < %s 2>&1 | FileCheck %s
+
+; Make sure we don't crash.
+define void @pr89959() {
+; CHECK-LABEL: define void @pr89959() {
+; CHECK-NEXT:  top:
+; CHECK-NEXT:br label [[L3:%.*]]
+; CHECK:   L3:
+; CHECK-NEXT:[[VALUE_PHI:%.*]] = phi ptr [ null, [[TOP:%.*]] ], [ 
[[TMP0:%.*]], [[L13:%.*]] ]
+; CHECK-NEXT:[[TMP0]] = getelementptr i8, ptr [[VALUE_PHI]], i64 8
+; CHECK-NEXT:[[DOTNOT:%.*]] = icmp ule ptr [[VALUE_PHI]], null
+; CHECK-NEXT:br i1 [[DOTNOT]], label [[L13]], label [[L15:%.*]]
+; CHECK:   L13:
+; CHECK-NEXT:br label [[L3]]
+; CHECK:   L15:
+; CHECK-NEXT:ret void
+;
+top:
+  br label %L3
+
+L3:
+  %value_phi = phi ptr [ null, %top ], [ %0, %L13 ]
+  %0 = getelementptr i8, ptr %value_phi, i64 8
+  %.not = icmp ule ptr %value_phi, null
+  br i1 %.not, label %L13, label %L15
+
+L13:
+  br label %L3
+
+L15:
+  ret void
+}



___
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/18.x: [IRCE] Skip icmp ptr in `InductiveRangeCheck::parseRangeCheckICmp` (#89967) (PR #90182)

2024-04-29 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/90182
___
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/18.x: [IRCE] Skip icmp ptr in `InductiveRangeCheck::parseRangeCheckICmp` (#89967) (PR #90182)

2024-04-29 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/90182

>From abf6b13085fbffe6d0384420d9bf562e2f1698c8 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Fri, 26 Apr 2024 16:25:33 +0800
Subject: [PATCH] [IRCE] Skip icmp ptr in
 `InductiveRangeCheck::parseRangeCheckICmp` (#89967)

Fixes https://github.com/llvm/llvm-project/issues/89959.

(cherry picked from commit 22da5a6e34ed6146752b24d9156a678b50fddaef)
---
 .../Scalar/InductiveRangeCheckElimination.cpp |  3 ++
 llvm/test/Transforms/IRCE/pr89959.ll  | 33 +++
 2 files changed, 36 insertions(+)
 create mode 100644 llvm/test/Transforms/IRCE/pr89959.ll

diff --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp 
b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
index 9df28747570c4d..104e8ceb796700 100644
--- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -279,6 +279,9 @@ bool InductiveRangeCheck::parseRangeCheckICmp(Loop *L, 
ICmpInst *ICI,
   Value *LHS = ICI->getOperand(0);
   Value *RHS = ICI->getOperand(1);
 
+  if (!LHS->getType()->isIntegerTy())
+return false;
+
   // Canonicalize to the `Index Pred Invariant` comparison
   if (IsLoopInvariant(LHS)) {
 std::swap(LHS, RHS);
diff --git a/llvm/test/Transforms/IRCE/pr89959.ll 
b/llvm/test/Transforms/IRCE/pr89959.ll
new file mode 100644
index 00..dc7c0dfbc57a97
--- /dev/null
+++ b/llvm/test/Transforms/IRCE/pr89959.ll
@@ -0,0 +1,33 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 4
+; RUN: opt -passes=irce -S < %s 2>&1 | FileCheck %s
+
+; Make sure we don't crash.
+define void @pr89959() {
+; CHECK-LABEL: define void @pr89959() {
+; CHECK-NEXT:  top:
+; CHECK-NEXT:br label [[L3:%.*]]
+; CHECK:   L3:
+; CHECK-NEXT:[[VALUE_PHI:%.*]] = phi ptr [ null, [[TOP:%.*]] ], [ 
[[TMP0:%.*]], [[L13:%.*]] ]
+; CHECK-NEXT:[[TMP0]] = getelementptr i8, ptr [[VALUE_PHI]], i64 8
+; CHECK-NEXT:[[DOTNOT:%.*]] = icmp ule ptr [[VALUE_PHI]], null
+; CHECK-NEXT:br i1 [[DOTNOT]], label [[L13]], label [[L15:%.*]]
+; CHECK:   L13:
+; CHECK-NEXT:br label [[L3]]
+; CHECK:   L15:
+; CHECK-NEXT:ret void
+;
+top:
+  br label %L3
+
+L3:
+  %value_phi = phi ptr [ null, %top ], [ %0, %L13 ]
+  %0 = getelementptr i8, ptr %value_phi, i64 8
+  %.not = icmp ule ptr %value_phi, null
+  br i1 %.not, label %L13, label %L15
+
+L13:
+  br label %L3
+
+L15:
+  ret void
+}

___
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] ee5bb0c - Fix Objective-C++ Sret of non-trivial data types on Windows ARM64 (#88671)

2024-04-29 Thread Tom Stellard via llvm-branch-commits

Author: Hugo Melder
Date: 2024-04-29T15:45:36-07:00
New Revision: ee5bb0c956679f43da48b914800846d57a6380d2

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

LOG: Fix Objective-C++ Sret of non-trivial data types on Windows ARM64 (#88671)

Linked to https://github.com/gnustep/libobjc2/pull/289.

More information can be found in issue: #88273.

My solution involves creating a new message-send function for this
calling convention when targeting MSVC. Additional information is
available in the libobjc2 pull request.

I am unsure whether we should check for a runtime version where
objc_msgSend_stret2_np is guaranteed to be present or leave it as is,
considering it remains a critical bug. What are your thoughts about this
@davidchisnall?

(cherry picked from commit 3dcd2ccab338d87deb1ca506df1376123667)

Added: 
clang/test/CodeGenObjCXX/msabi-stret-arm64.mm

Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGObjCGNU.cpp
clang/lib/CodeGen/CodeGenModule.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 28c211aa631e4d..a6a2f3595fe7db 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1581,6 +1581,11 @@ bool CodeGenModule::ReturnTypeUsesSRet(const 
CGFunctionInfo &FI) {
   return RI.isIndirect() || (RI.isInAlloca() && RI.getInAllocaSRet());
 }
 
+bool CodeGenModule::ReturnTypeHasInReg(const CGFunctionInfo &FI) {
+  const auto &RI = FI.getReturnInfo();
+  return RI.getInReg();
+}
+
 bool CodeGenModule::ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI) {
   return ReturnTypeUsesSRet(FI) &&
  getTargetCodeGenInfo().doesReturnSlotInterfereWithArgs();

diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index a36b0cdddaf0af..05e3f8d4bfc2a3 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -2903,23 +2903,29 @@ CGObjCGNU::GenerateMessageSend(CodeGenFunction &CGF,
   break;
 case CodeGenOptions::Mixed:
 case CodeGenOptions::NonLegacy:
+  StringRef name = "objc_msgSend";
   if (CGM.ReturnTypeUsesFPRet(ResultType)) {
-imp =
-CGM.CreateRuntimeFunction(llvm::FunctionType::get(IdTy, IdTy, 
true),
-  "objc_msgSend_fpret")
-.getCallee();
+name = "objc_msgSend_fpret";
   } else if (CGM.ReturnTypeUsesSRet(MSI.CallInfo)) {
-// The actual types here don't matter - we're going to bitcast the
-// function anyway
-imp =
-CGM.CreateRuntimeFunction(llvm::FunctionType::get(IdTy, IdTy, 
true),
-  "objc_msgSend_stret")
-.getCallee();
-  } else {
-imp = CGM.CreateRuntimeFunction(
- llvm::FunctionType::get(IdTy, IdTy, true), "objc_msgSend")
-  .getCallee();
+name = "objc_msgSend_stret";
+
+// The address of the memory block is be passed in x8 for POD type,
+// or in x0 for non-POD type (marked as inreg).
+bool shouldCheckForInReg =
+CGM.getContext()
+.getTargetInfo()
+.getTriple()
+.isWindowsMSVCEnvironment() &&
+CGM.getContext().getTargetInfo().getTriple().isAArch64();
+if (shouldCheckForInReg && CGM.ReturnTypeHasInReg(MSI.CallInfo)) {
+  name = "objc_msgSend_stret2";
+}
   }
+  // The actual types here don't matter - we're going to bitcast the
+  // function anyway
+  imp = CGM.CreateRuntimeFunction(llvm::FunctionType::get(IdTy, IdTy, 
true),
+  name)
+.getCallee();
 }
 
   // Reset the receiver in case the lookup modified it

diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index ec34680fd3f7e6..d9ece4d98eecae 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1239,6 +1239,9 @@ class CodeGenModule : public CodeGenTypeCache {
   /// Return true iff the given type uses 'sret' when used as a return type.
   bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
 
+  /// Return true iff the given type has `inreg` set.
+  bool ReturnTypeHasInReg(const CGFunctionInfo &FI);
+
   /// Return true iff the given type uses an argument slot when 'sret' is used
   /// as a return type.
   bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI);

diff  --git a/clang/test/CodeGenObjCXX/msabi-stret-arm64.mm 
b/clang/test/CodeGenObjCXX/msabi-stret-arm64.mm
new file mode 100644
index 00..3bbdbebc5cb576
--- /dev/null
+++ b/clang/test/CodeGenObjCXX/msabi-stret-arm64.mm
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -triple aarch64-pc-windows-msvc -fobjc-ru

[llvm-branch-commits] [clang] [Clang] Handle structs with inner structs and no fields (#89126) (PR #90133)

2024-04-29 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/90133

>From be6eecf824cb435aea3837e9447b6dd70c11d978 Mon Sep 17 00:00:00 2001
From: Bill Wendling <5993918+bwendl...@users.noreply.github.com>
Date: Fri, 19 Apr 2024 12:48:33 -0700
Subject: [PATCH] [Clang] Handle structs with inner structs and no fields
 (#89126)

A struct that declares an inner struct, but no fields, won't have a
field count. So getting the offset of the inner struct fails. This
happens in both C and C++:

  struct foo {
struct bar {
  int Quantizermatrix[];
};
  };

Here 'struct foo' has no fields.

Closes: https://github.com/llvm/llvm-project/issues/88931
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 25 +++-
 clang/test/CodeGen/attr-counted-by-pr88931.c  | 40 +++
 .../test/CodeGen/attr-counted-by-pr88931.cpp  | 21 ++
 3 files changed, 75 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-counted-by-pr88931.c
 create mode 100644 clang/test/CodeGen/attr-counted-by-pr88931.cpp

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a4f26a6f0eb19b..44ddd2428b10f5 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -823,29 +823,32 @@ const FieldDecl 
*CodeGenFunction::FindFlexibleArrayMemberField(
 ASTContext &Ctx, const RecordDecl *RD, StringRef Name, uint64_t &Offset) {
   const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
   getLangOpts().getStrictFlexArraysLevel();
-  unsigned FieldNo = 0;
-  bool IsUnion = RD->isUnion();
+  uint32_t FieldNo = 0;
 
-  for (const Decl *D : RD->decls()) {
-if (const auto *Field = dyn_cast(D);
-Field && (Name.empty() || Field->getNameAsString() == Name) &&
+  if (RD->isImplicit())
+return nullptr;
+
+  for (const FieldDecl *FD : RD->fields()) {
+if ((Name.empty() || FD->getNameAsString() == Name) &&
 Decl::isFlexibleArrayMemberLike(
-Ctx, Field, Field->getType(), StrictFlexArraysLevel,
+Ctx, FD, FD->getType(), StrictFlexArraysLevel,
 /*IgnoreTemplateOrMacroSubstitution=*/true)) {
   const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
   Offset += Layout.getFieldOffset(FieldNo);
-  return Field;
+  return FD;
 }
 
-if (const auto *Record = dyn_cast(D))
-  if (const FieldDecl *Field =
-  FindFlexibleArrayMemberField(Ctx, Record, Name, Offset)) {
+QualType Ty = FD->getType();
+if (Ty->isRecordType()) {
+  if (const FieldDecl *Field = FindFlexibleArrayMemberField(
+  Ctx, Ty->getAsRecordDecl(), Name, Offset)) {
 const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
 Offset += Layout.getFieldOffset(FieldNo);
 return Field;
   }
+}
 
-if (!IsUnion && isa(D))
+if (!RD->isUnion())
   ++FieldNo;
   }
 
diff --git a/clang/test/CodeGen/attr-counted-by-pr88931.c 
b/clang/test/CodeGen/attr-counted-by-pr88931.c
new file mode 100644
index 00..520ebd09973284
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-pr88931.c
@@ -0,0 +1,40 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 
-Wno-missing-declarations -emit-llvm -o - %s | FileCheck %s
+
+struct foo {
+  int x,y,z;
+  struct bar {
+int count;
+int array[] __attribute__((counted_by(count)));
+  };
+};
+
+void init(void * __attribute__((pass_dynamic_object_size(0;
+
+// CHECK-LABEL: define dso_local void @test1(
+// CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ARRAY:%.*]] = getelementptr inbounds [[STRUCT_BAR:%.*]], 
ptr [[P]], i64 0, i32 1
+// CHECK-NEXT:tail call void @init(ptr noundef nonnull [[ARRAY]], i64 
noundef -1) #[[ATTR2:[0-9]+]]
+// CHECK-NEXT:ret void
+//
+void test1(struct bar *p) {
+  init(p->array);
+}
+
+struct mux {
+  int count;
+  int array[] __attribute__((counted_by(count)));
+};
+
+struct bux { struct mux x; };
+
+// CHECK-LABEL: define dso_local void @test2(
+// CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @init(ptr noundef [[P]], i64 noundef -1) 
#[[ATTR2]]
+// CHECK-NEXT:ret void
+//
+void test2(struct bux *p) {
+  init(p);
+}
diff --git a/clang/test/CodeGen/attr-counted-by-pr88931.cpp 
b/clang/test/CodeGen/attr-counted-by-pr88931.cpp
new file mode 100644
index 00..2a8cc1d07e50d9
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-pr88931.cpp
@@ -0,0 +1,21 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -Wall -emit-llvm -o - 
%s | FileCheck %s
+
+struct foo {
+  struct bar {
+int array[];
+bar();
+  };
+};
+
+void init(void * __attribut

[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/3] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/3] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

>From 5806a5a17631587995d75f0ea5ffe016fac809b8 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Fri, 12 Apr 2024 14:25:38 -0700
Subject: [PATCH 3/3] Update clang/docs/LanguageExtensions.rst

Co-authored-by: Aaron Ballman 
---
 clang/docs/LanguageExtensions.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 9078f1c76761bd..a4483ef4f76d00 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3507,7 +3507,7 @@ precedence.
 ``true``, allowing all checks.
 
 Parameter ``kind`` is a string literal representing a user selected kind for
-guarded check. It's unused now. It will enable kind specific lowering in 
future.
+guarded check. It's unused now. It will enable kind-specific lowering in 
future.
 E.g. a higher hotness cutoff can be used for more expensive kind of check.
 
 Query for this feature with ``__has_builtin(__builtin_allow_runtime_check)``.

___
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] [llvm] [InstCombiner] Remove trivially dead `llvm.allow.{runtime, ubsan}.check()` (PR #84851)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/84851

>From c15aa098b7a8db614f574d47c220852674d4681d Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Mon, 11 Mar 2024 17:13:07 -0700
Subject: [PATCH 1/2] rebase

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp |  6 +-
 clang/lib/CodeGen/CGExpr.cpp  | 15 +---
 clang/test/CodeGen/remote-traps.c | 23 +
 .../Instrumentation/RemoveTrapsPass.cpp   | 26 +++---
 .../Transforms/RemoveTraps/remove-traps.ll| 89 ++-
 5 files changed, 43 insertions(+), 116 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7e53469a48d42c..82b30b8d815629 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -100,9 +100,9 @@ using namespace llvm;
 namespace llvm {
 extern cl::opt PrintPipelinePasses;
 
-static cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
-   cl::desc("Insert remove-traps pass."),
-   cl::init(false));
+cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
+cl::desc("Insert remove-traps pass."),
+cl::init(false));
 
 // Experiment to move sanitizers earlier.
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 3a27622f165995..59a7fe8925001c 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -56,14 +56,7 @@ using namespace CodeGen;
 // Experiment to make sanitizers easier to debug
 static llvm::cl::opt ClSanitizeDebugDeoptimization(
 "ubsan-unique-traps", llvm::cl::Optional,
-llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check."),
-llvm::cl::init(false));
-
-// TODO: Introduce frontend options to enabled per sanitizers, similar to
-// `fsanitize-trap`.
-static llvm::cl::opt ClSanitizeExpHot(
-"ubsan-exp-hot", llvm::cl::Optional,
-llvm::cl::desc("Pass UBSAN checks if `llvm.experimental.hot()` is true."),
+llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check"),
 llvm::cl::init(false));
 
 //======//
@@ -3812,12 +3805,6 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
 SanitizerHandler CheckHandlerID) {
   llvm::BasicBlock *Cont = createBasicBlock("cont");
 
-  if (ClSanitizeExpHot) {
-Checked =
-Builder.CreateOr(Checked, Builder.CreateCall(CGM.getIntrinsic(
-  llvm::Intrinsic::experimental_hot)));
-  }
-
   // If we're optimizing, collapse all calls to trap down to just one per
   // check-type per function to save on code size.
   if ((int)TrapBBs.size() <= CheckHandlerID)
diff --git a/clang/test/CodeGen/remote-traps.c 
b/clang/test/CodeGen/remote-traps.c
index 16e4ebecb5c326..6751afb96d25f2 100644
--- a/clang/test/CodeGen/remote-traps.c
+++ b/clang/test/CodeGen/remote-traps.c
@@ -1,7 +1,5 @@
-// RUN: %clang_cc1 -O1 %s -o - -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -ubsan-exp-hot | FileCheck %s 
-// RUN: %clang_cc1 -O1 %s -o - -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -ubsan-exp-hot -mllvm 
-clang-remove-traps -mllvm -remove-traps-random-rate=1 %s -o - | FileCheck %s 
--check-prefixes=REMOVE
-
-#include 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow %s -o - | FileCheck %s 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -clang-remove-traps -mllvm 
-remove-traps-random-rate=1 %s -o - | FileCheck %s --implicit-check-not="call 
void @llvm.ubsantrap" --check-prefixes=REMOVE
 
 int test(int x) {
   return x + 123;
@@ -14,19 +12,4 @@ int test(int x) {
 // CHECK-NEXT: unreachable
 
 // REMOVE-LABEL: define {{.*}}i32 @test(
-// REMOVE: add i32 %x, 123
-// REMOVE-NEXT: ret i32
-
-
-bool experimental_hot() __asm("llvm.experimental.hot");
-
-bool test_asm() {
-  return experimental_hot();
-}
-
-// CHECK-LABEL: define {{.*}}i1 @test_asm(
-// CHECK: [[R:%.*]] = tail call zeroext i1 @llvm.experimental.hot()
-// CHECK: ret i1 [[R]]
-
-// REMOVE-LABEL: define {{.*}}i1 @test_asm(
-// REMOVE: ret i1 true
+// REMOVE: call { i32, i1 } @llvm.sadd.with.overflow.i32(
diff --git a/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp 
b/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
index fa4716f2e7a403..d87f7482a21d25 100644
--- a/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
+++ b/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
@@ -11,7 +11,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/ProfileSummaryInfo.h"
-#include "l

[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
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] b9f0b0e - clang-format

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2024-04-16T17:31:38-07:00
New Revision: b9f0b0e8b44018ef0d82252bc55830f165f0f5c4

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

LOG: clang-format

Added: 


Modified: 
clang/include/clang/Sema/Initialization.h
clang/include/clang/Sema/Overload.h
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Initialization.h 
b/clang/include/clang/Sema/Initialization.h
index 2072cd8d1c3ef8..0cae6d353d22bc 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -1402,9 +1402,7 @@ class InitializationSequence {
 
   /// Retrieve a reference to the candidate set when overload
   /// resolution fails.
-  OverloadCandidateSet &getFailedCandidateSet() {
-return FailedCandidateSet;
-  }
+  OverloadCandidateSet &getFailedCandidateSet() { return FailedCandidateSet; }
 
   /// Get the overloading result, for when the initialization
   /// sequence failed due to a bad overload.

diff  --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index 76311b00d2fc58..a49cc6778d46b0 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -972,7 +972,8 @@ class Sema;
   private:
 friend class OverloadCandidateSet;
 OverloadCandidate()
-: IsSurrogate(false), IsADLCandidate(CallExpr::NotADL), 
RewriteKind(CRK_None) {}
+: IsSurrogate(false), IsADLCandidate(CallExpr::NotADL),
+  RewriteKind(CRK_None) {}
   };
 
   /// OverloadCandidateSet - A set of overload candidates, used in C++
@@ -1095,8 +1096,7 @@ class Sema;
 /// instead.
 /// FIXME: Now that this only allocates ImplicitConversionSequences, do we
 /// want to un-generalize this?
-template 
-T *slabAllocate(unsigned N) {
+template  T *slabAllocate(unsigned N) {
   // It's simpler if this doesn't need to consider alignment.
   static_assert(alignof(T) == alignof(void *),
 "Only works for pointer-aligned types.");

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index fb7a80ab02846c..6afcc56c73540b 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -9749,7 +9749,8 @@ bool InitializationSequence::Diagnose(Sema &S,
   break;
 
 case OR_No_Viable_Function: {
-  auto Cands = FailedCandidateSet.CompleteCandidates(S, OCD_AllCandidates, 
Args);
+  auto Cands =
+  FailedCandidateSet.CompleteCandidates(S, OCD_AllCandidates, Args);
   if (!S.RequireCompleteType(Kind.getLocation(),
  DestType.getNonReferenceType(),
   diag::err_typecheck_nonviable_condition_incomplete,
@@ -9764,8 +9765,8 @@ bool InitializationSequence::Diagnose(Sema &S,
 }
 case OR_Deleted: {
   OverloadCandidateSet::iterator Best;
-  OverloadingResult Ovl
-= FailedCandidateSet.BestViableFunction(S, Kind.getLocation(), Best);
+  OverloadingResult Ovl =
+  FailedCandidateSet.BestViableFunction(S, Kind.getLocation(), Best);
 
   StringLiteral *Msg = Best->Function->getDeletedMessage();
   S.Diag(Kind.getLocation(), diag::err_typecheck_deleted_function)
@@ -10013,8 +10014,8 @@ bool InitializationSequence::Diagnose(Sema &S,
 
   case OR_Deleted: {
 OverloadCandidateSet::iterator Best;
-OverloadingResult Ovl
-  = FailedCandidateSet.BestViableFunction(S, Kind.getLocation(), Best);
+OverloadingResult Ovl =
+FailedCandidateSet.BestViableFunction(S, Kind.getLocation(), Best);
 if (Ovl != OR_Deleted) {
   S.Diag(Kind.getLocation(), diag::err_ovl_deleted_init)
   << DestType << ArgsRange;
@@ -10093,8 +10094,8 @@ bool InitializationSequence::Diagnose(Sema &S,
 S.Diag(Kind.getLocation(), diag::err_selected_explicit_constructor)
   << Args[0]->getSourceRange();
 OverloadCandidateSet::iterator Best;
-OverloadingResult Ovl
-  = FailedCandidateSet.BestViableFunction(S, Kind.getLocation(), Best);
+OverloadingResult Ovl =
+FailedCandidateSet.BestViableFunction(S, Kind.getLocation(), Best);
 (void)Ovl;
 assert(Ovl == OR_Success && "Inconsistent overload resolution");
 CXXConstructorDecl *CtorDecl = cast(Best->Function);



___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Aaron Ballman via llvm-branch-commits


@@ -3464,6 +3464,34 @@ Query for this feature with 
``__has_builtin(__builtin_trap)``.
 
 ``__builtin_arm_trap`` is lowered to the ``llvm.aarch64.break`` builtin, and 
then to ``brk #payload``.
 
+``__builtin_allow_runtime_check``

AaronBallman wrote:

> It needs to be compiler time lowered, so I think it should literals.

In that case, I think we want *constant expression* not just literal, right? 
e.g.,
```
constexpr const char *name = "name of check";
if (__builtin_allow_runtime_check(name)) {
}
```
is still able to be lowered at compile time. The reason I ask is because I'm 
thinking about template metaprogramming cases where you might want to do 
something along the lines of:
```
template 
struct S {
  void mem_fun() {
if (__builtin_allow_runtime_check(Ty::check_name) && stuff) {
}
  }
};
```
but maybe this is not a compelling use case? I don't insist on constant 
expression support, more just trying to verify that we support the expected 
usage patterns.

https://github.com/llvm/llvm-project/pull/87568
___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Aaron Ballman via llvm-branch-commits


@@ -3464,6 +3464,54 @@ Query for this feature with 
``__has_builtin(__builtin_trap)``.
 
 ``__builtin_arm_trap`` is lowered to the ``llvm.aarch64.break`` builtin, and 
then to ``brk #payload``.
 
+``__builtin_allow_runtime_check``
+-
+
+``__builtin_allow_runtime_check`` return true if the check at the current
+program location should be executed. It is expected to be used to implement
+``assert`` like checks which can be safely removed by optimizer.
+
+**Syntax**:
+
+.. code-block:: c++
+
+bool __builtin_allow_runtime_check(const char* kind)
+
+**Example of use**:
+
+.. code-block:: c++
+
+  if (__builtin_allow_runtime_check("mycheck") && !ExpensiveCheck()) {
+ abort();
+  }
+
+**Description**
+
+``__builtin_allow_runtime_check`` is lowered to ` ``llvm.allow.runtime.check``
+`_
+builtin.
+
+The ``__builtin_allow_runtime_check()`` is expected to be used with control
+flow conditions such as in ``if`` to guard expensive runtime checks. The
+specific rules for selecting permitted checks can differ and are controlled by
+the compiler options.
+
+Flags to control checks:
+* ``-mllvm -lower-allow-check-percentile-cutoff-hot=N`` where N is PGO hotness
+cutoff in range ``[0, 99]`` to disallow checks in hot code.
+* ``-mllvm -lower-allow-check-random-rate=P`` where P is number in range
+``[0.0, 1.0]`` representation probability of keeping a check.
+* If both flags are specified, ``-lower-allow-check-random-rate`` takes
+precedence.
+* If none is specified, ``__builtin_allow_runtime_check`` is lowered as
+``true``, allowing all checks.
+
+Parameter ``kind`` is a string literal representing a user selected kind for
+guarded check. It's unused now. It will enable kind specific lowering in 
future.

AaronBallman wrote:

```suggestion
guarded check. It's unused now. It will enable kind-specific lowering in future.
```

https://github.com/llvm/llvm-project/pull/87568
___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka edited 
https://github.com/llvm/llvm-project/pull/87568
___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits


@@ -3464,6 +3464,34 @@ Query for this feature with 
``__has_builtin(__builtin_trap)``.
 
 ``__builtin_arm_trap`` is lowered to the ``llvm.aarch64.break`` builtin, and 
then to ``brk #payload``.
 
+``__builtin_allow_runtime_check``

vitalybuka wrote:

I've started RFC, as @efriedma-quic suggested
https://discourse.llvm.org/t/rfc-introduce-new-clang-builtin-builtin-allow-runtime-check/78281

It needs to be compiler time lowered, so I think it should literals. 



https://github.com/llvm/llvm-project/pull/87568
___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits


@@ -3233,6 +3233,17 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 if (BuiltinCountZeroBitsGeneric(*this, TheCall))
   return ExprError();
 break;
+
+  case Builtin::BI__builtin_allow_runtime_check: {
+Expr *Arg = TheCall->getArg(0);
+// Check if the argument is a string literal.
+if (!isa(Arg->IgnoreParenImpCasts())) {

vitalybuka wrote:

My interest is in using this feature to implement `assert` like macros which 
will be enabled in cold code, and optimized out in hot.  E.g. MY_ASSERT1, 
MY_ASSERT2... 
Each macro can provide own kind as literal. Number of different kinds is 
supposed to be limited. So literal looks enough for me.
We can relax in the future, restricting could be harder.

https://github.com/llvm/llvm-project/pull/87568
___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Aaron Ballman via llvm-branch-commits


@@ -3464,6 +3464,34 @@ Query for this feature with 
``__has_builtin(__builtin_trap)``.
 
 ``__builtin_arm_trap`` is lowered to the ``llvm.aarch64.break`` builtin, and 
then to ``brk #payload``.
 
+``__builtin_allow_runtime_check``

AaronBallman wrote:

The docs aren't particularly clear to me -- why would the check at the current 
program location ever NOT be executed? What strings can be passed in? What 
compiler options impact it? Will it only accept string literals or are runtime 
values fine?

https://github.com/llvm/llvm-project/pull/87568
___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Aaron Ballman via llvm-branch-commits


@@ -3233,6 +3233,17 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 if (BuiltinCountZeroBitsGeneric(*this, TheCall))
   return ExprError();
 break;
+
+  case Builtin::BI__builtin_allow_runtime_check: {
+Expr *Arg = TheCall->getArg(0);
+// Check if the argument is a string literal.
+if (!isa(Arg->IgnoreParenImpCasts())) {

AaronBallman wrote:

This might be a reasonable restriction, but consider other cases like: 
`constexpr` variable of string type, `constexpr` function call that returns a 
`const char *`, `_Generic` that results in a string constant, etc. Would those 
be reasonable to support?

https://github.com/llvm/llvm-project/pull/87568
___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

vitalybuka wrote:

I assume clang/docs/LanguageExtensions.rst counts as 
https://github.com/llvm/llvm-project/blob/main/clang/CodeOwners.rst#all-parts-of-clang-not-covered-by-someone-else

https://github.com/llvm/llvm-project/pull/87568
___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Eli Friedman via llvm-branch-commits

efriedma-quic wrote:

I think it's worth re-posting the builtin as a separate RFC on Discourse, since 
the original RFC hadn't settled on the exact design for the clang builtin 
you're using here.

Code changes look fine.

https://github.com/llvm/llvm-project/pull/87568
___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
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] 2f46953 - Revert "[clang][UBSan] Add implicit conversion check for bitfields (#75481)"

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

Author: Vitaly Buka
Date: 2024-04-03T10:25:39-07:00
New Revision: 2f4695348d335ea70b167b738c48019d591c86b0

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

LOG: Revert "[clang][UBSan] Add implicit conversion check for bitfields 
(#75481)"

This reverts commit 1189e87951e59a81ee097eae847c06008276fef1.
This reverts commit 450f1952aced87584a53485d1ba1c2f77c3835a1.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/UndefinedBehaviorSanitizer.rst
clang/include/clang/Basic/Sanitizers.def
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/Driver/fsanitize.c
compiler-rt/lib/ubsan/ubsan_handlers.cpp
compiler-rt/lib/ubsan/ubsan_handlers.h

Removed: 
clang/test/CodeGen/ubsan-bitfield-conversion.c
clang/test/CodeGenCXX/ubsan-bitfield-conversion.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e4c0e49ed6fc1c..8fc925350849cd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -198,10 +198,6 @@ Non-comprehensive list of changes in this release
 
 New Compiler Flags
 --
-- ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and
-  sign change.
-- ``-fsanitize=implicit-integer-conversion`` a group that replaces the previous
-  group ``-fsanitize=implicit-conversion``.
 
 - ``-Wmissing-designated-field-initializers``, grouped under 
``-Wmissing-field-initializers``.
   This diagnostic can be disabled to make ``-Wmissing-field-initializers`` 
behave
@@ -215,9 +211,6 @@ Modified Compiler Flags
 - Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under
   ``-Wreturn-type``, and moved some of the diagnostics previously controlled by
   ``-Wreturn-type`` under this new flag. Fixes #GH72116.
-- ``-fsanitize=implicit-conversion`` is now a group for both
-  ``-fsanitize=implicit-integer-conversion`` and
-  ``-fsanitize=implicit-bitfield-conversion``.
 
 - Added ``-Wcast-function-type-mismatch`` under the ``-Wcast-function-type``
   warning group. Moved the diagnostic previously controlled by

diff  --git a/clang/docs/UndefinedBehaviorSanitizer.rst 
b/clang/docs/UndefinedBehaviorSanitizer.rst
index 531d56e313826c..8f58c92bd2a163 100644
--- a/clang/docs/UndefinedBehaviorSanitizer.rst
+++ b/clang/docs/UndefinedBehaviorSanitizer.rst
@@ -148,11 +148,6 @@ Available checks are:
  Issues caught by this sanitizer are not undefined behavior,
  but are often unintentional.
   -  ``-fsanitize=integer-divide-by-zero``: Integer division by zero.
-  -  ``-fsanitize=implicit-bitfield-conversion``: Implicit conversion from
- integer of larger bit width to smaller bitfield, if that results in data
- loss. This includes unsigned/signed truncations and sign changes, 
similarly
- to how the ``-fsanitize=implicit-integer-conversion`` group works, but
- explicitly for bitfields.
   -  ``-fsanitize=nonnull-attribute``: Passing null pointer as a function
  parameter which is declared to never be null.
   -  ``-fsanitize=null``: Use of a null pointer or creation of a null
@@ -198,8 +193,8 @@ Available checks are:
  signed division overflow (``INT_MIN/-1``). Note that checks are still
  added even when ``-fwrapv`` is enabled. This sanitizer does not check for
  lossy implicit conversions performed before the computation (see
- ``-fsanitize=implicit-integer-conversion``). Both of these two issues are 
handled
- by ``-fsanitize=implicit-integer-conversion`` group of checks.
+ ``-fsanitize=implicit-conversion``). Both of these two issues are handled
+ by ``-fsanitize=implicit-conversion`` group of checks.
   -  ``-fsanitize=unreachable``: If control flow reaches an unreachable
  program point.
   -  ``-fsanitize=unsigned-integer-overflow``: Unsigned integer overflow, where
@@ -207,7 +202,7 @@ Available checks are:
  type. Unlike signed integer overflow, this is not undefined behavior, but
  it is often unintentional. This sanitizer does not check for lossy 
implicit
  conversions performed before such a computation
- (see ``-fsanitize=implicit-integer-conversion``).
+ (see ``-fsanitize=implicit-conversion``).
   -  ``-fsanitize=vla-bound``: A variable-length array whose bound
  does not evaluate to a positive value.
   -  ``-fsanitize=vptr``: Use of an object whose vptr indicates that it is of
@@ -229,15 +224,11 @@ You can also use the following check groups:
   -  ``-fsanitize=implicit-integer-arithmetic-value-change``: Catches implicit
  conversions that change the arithmetic value of the integer. Enables
  ``implicit-signed-integer-truncation`` and 
``implicit-integer-sign-change``.
-  -  ``-fsanitize=implicit-integer-conv

[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/87568

>From 7ca1d437690a8202cc000aa3a431c26e26b9c358 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:30:10 -0700
Subject: [PATCH 1/2] undo random change

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGBuiltin.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f4809f09e025a2..d95a016c25dc92 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3423,6 +3423,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateCall(FnAssume, ArgValue);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__builtin_assume_separate_storage: {
+const Expr *Arg0 = E->getArg(0);
+const Expr *Arg1 = E->getArg(1);
+
+Value *Value0 = EmitScalarExpr(Arg0);
+Value *Value1 = EmitScalarExpr(Arg1);
+
+Value *Values[] = {Value0, Value1};
+OperandBundleDefT OBD("separate_storage", Values);
+Builder.CreateAssumption(ConstantInt::getTrue(getLLVMContext()), {OBD});
+return RValue::get(nullptr);
+  }
   case Builtin::BI__builtin_allow_runtime_check: {
 StringRef Kind =
 cast(E->getArg(0)->IgnoreParenCasts())->getString();

>From 8bb91d88e0d394b61bef885ecf9303018a855bd0 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 3 Apr 2024 15:43:33 -0700
Subject: [PATCH 2/2] drop one IgnoreParenImpCasts

Created using spr 1.3.4
---
 clang/lib/Sema/SemaChecking.cpp   | 2 +-
 clang/test/Sema/builtin-allow-runtime-check.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 3ac456d5c54885..277836961a2951 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3237,7 +3237,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 break;
 
   case Builtin::BI__builtin_allow_runtime_check: {
-Expr *Arg = TheCall->getArg(0)->IgnoreParenImpCasts();
+Expr *Arg = TheCall->getArg(0);
 // Check if the argument is a string literal.
 if (!isa(Arg->IgnoreParenImpCasts())) {
   Diag(TheCall->getBeginLoc(), diag::err_expr_not_string_literal)
diff --git a/clang/test/Sema/builtin-allow-runtime-check.c 
b/clang/test/Sema/builtin-allow-runtime-check.c
index f4a94fa66321e5..b656861755 100644
--- a/clang/test/Sema/builtin-allow-runtime-check.c
+++ b/clang/test/Sema/builtin-allow-runtime-check.c
@@ -6,6 +6,8 @@ extern const char *str;
 int main(void) {
   int r = 0;
 
+  r |= __builtin_allow_runtime_check(); // expected-error {{too few arguments 
to function call}}
+
   r |= __builtin_allow_runtime_check(str); // expected-error {{expression is 
not a string literal}}
 
   r |= __builtin_allow_runtime_check(5); // expected-error {{incompatible 
integer to pointer conversion}} expected-error {{expression is not a string 
literal}}

___
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] [llvm] [clang][ubsan] Switch UBSAN optimization to `llvm.allow.{runtime, ubsan}.check()` (PR #84858)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/84858

>From 852eb20b4f091a535ef758407d8555798b0ad809 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 4 Apr 2024 16:17:19 -0700
Subject: [PATCH 1/2] [RISCV][GISel] Make register bank selection for unary and
 binary arithmetic ops more generic. (#87593)

This is inspired by AArch64's getSameKindOfOperandsMapping, but based on
what RISC-V currently needs.

This removes the special vector case for G_ADD/SUB and unifies integer
and FP operations into the same handler.

G_SEXTLOAD/ZEXTLOAD have been separated from integer since they should
only be scalar integer and never vector.
---
 .../RISCV/GISel/RISCVRegisterBankInfo.cpp | 45 ---
 1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp 
b/llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp
index 8534024b6002b6..86e44343b50865 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp
@@ -290,16 +290,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr 
&MI) const {
 
   switch (Opc) {
   case TargetOpcode::G_ADD:
-  case TargetOpcode::G_SUB: {
-if (MRI.getType(MI.getOperand(0).getReg()).isVector()) {
-  LLT Ty = MRI.getType(MI.getOperand(0).getReg());
-  return getInstructionMapping(
-  DefaultMappingID, /*Cost=*/1,
-  getVRBValueMapping(Ty.getSizeInBits().getKnownMinValue()),
-  NumOperands);
-}
-  }
-LLVM_FALLTHROUGH;
+  case TargetOpcode::G_SUB:
   case TargetOpcode::G_SHL:
   case TargetOpcode::G_ASHR:
   case TargetOpcode::G_LSHR:
@@ -320,10 +311,6 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr 
&MI) const {
   case TargetOpcode::G_PTR_ADD:
   case TargetOpcode::G_PTRTOINT:
   case TargetOpcode::G_INTTOPTR:
-  case TargetOpcode::G_SEXTLOAD:
-  case TargetOpcode::G_ZEXTLOAD:
-return getInstructionMapping(DefaultMappingID, /*Cost=*/1, GPRValueMapping,
- NumOperands);
   case TargetOpcode::G_FADD:
   case TargetOpcode::G_FSUB:
   case TargetOpcode::G_FMUL:
@@ -334,10 +321,34 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr 
&MI) const {
   case TargetOpcode::G_FMAXNUM:
   case TargetOpcode::G_FMINNUM: {
 LLT Ty = MRI.getType(MI.getOperand(0).getReg());
-return getInstructionMapping(DefaultMappingID, /*Cost=*/1,
- getFPValueMapping(Ty.getSizeInBits()),
- NumOperands);
+TypeSize Size = Ty.getSizeInBits();
+
+const ValueMapping *Mapping;
+if (Ty.isVector())
+  Mapping = getVRBValueMapping(Size.getKnownMinValue());
+else if (isPreISelGenericFloatingPointOpcode(Opc))
+  Mapping = getFPValueMapping(Size.getFixedValue());
+else
+  Mapping = GPRValueMapping;
+
+#ifndef NDEBUG
+// Make sure all the operands are using similar size and type.
+for (unsigned Idx = 1; Idx != NumOperands; ++Idx) {
+  LLT OpTy = MRI.getType(MI.getOperand(Idx).getReg());
+  assert(Ty.isVector() == OpTy.isVector() &&
+ "Operand has incompatible type");
+  // Don't check size for GPR.
+  if (OpTy.isVector() || isPreISelGenericFloatingPointOpcode(Opc))
+assert(Size == OpTy.getSizeInBits() && "Operand has incompatible 
size");
+}
+#endif // End NDEBUG
+
+return getInstructionMapping(DefaultMappingID, 1, Mapping, NumOperands);
   }
+  case TargetOpcode::G_SEXTLOAD:
+  case TargetOpcode::G_ZEXTLOAD:
+return getInstructionMapping(DefaultMappingID, /*Cost=*/1, GPRValueMapping,
+ NumOperands);
   case TargetOpcode::G_IMPLICIT_DEF: {
 Register Dst = MI.getOperand(0).getReg();
 LLT DstTy = MRI.getType(Dst);

>From 634a277f9750af0b74b8e40e3fb509ca74b66fe1 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Mon, 11 Mar 2024 16:58:15 -0700
Subject: [PATCH 2/2] [clang][ubsan] Switch UBSAN optimization to
 `llvm.allow.{runtime,ubsan}.check()`

Intrinsic introduced with #84850. Intrinsics improves performance
by 3% comparing to removing traps (on
"test-suite/MultiSource/Benchmarks" with PGO+ThinLTO).

The pass will be renamed with #84853.

RFC: 
https://discourse.llvm.org/t/rfc-add-llvm-experimental-hot-intrinsic-or-llvm-hot/77641

Reviewers: aeubanks, nikic, kstoimenov, dvyukov

Reviewed By: kstoimenov

Pull Request: https://github.com/llvm/llvm-project/pull/84858
---
 clang/test/CodeGen/remote-traps.c |  37 --
 .../Instrumentation/RemoveTrapsPass.cpp   |  25 ++--
 .../Transforms/RemoveTraps/remove-traps.ll| 115 ++
 3 files changed, 105 insertions(+), 72 deletions(-)
 delete mode 100644 clang/test/CodeGen/remote-traps.c

diff --git a/clang/test/CodeGen/remote-traps.c 
b/clang/test/CodeGen/remote-traps.c
deleted file mode 100644
index b12c2c6e23b2d1..00
--- a/clang/test/CodeGen/remote-traps.c
+++ /dev/null
@

[llvm-branch-commits] [clang] [compiler-rt] [flang] [libc] [libcxx] [lldb] [llvm] [mlir] [GlobalISel] Handle more commutable instructions in `commute_constant_to_rhs` (PR #87424)

2024-04-29 Thread via llvm-branch-commits
Jan =?utf-8?q?Kokemüller?= ,Michael Buch
 ,Spenser Bauman ,Joseph
 Huber ,Daniil Kovalev ,A.
 Jiang =?utf-8?q?,?=Ryotaro KASUGA
 ,Joseph Huber ,Matthias
 Springer ,Craig Topper ,Jan Svoboda
 ,Fangrui Song ,Joseph Huber
 ,Cinhi Young ,Vinayak Dev
 <104419489+vinayakd...@users.noreply.github.com>,Fangrui Song 
,Vinayak
 Dev <104419489+vinayakd...@users.noreply.github.com>,Chuanqi Xu
 ,Jonas Devlieghere 
,smanna12
 ,Slava Zakharin ,Mingming Liu
 ,hanbeom ,Bevin Hansson
 <59652494+bevin-hans...@users.noreply.github.com>,Chuanqi Xu
 ,Chuanqi Xu ,Phoebe
 Wang ,David Green ,Phoebe Wang
 ,Elizaveta Noskova
 <159026035+enoskova...@users.noreply.github.com>,Chuanqi Xu
 ,Chuanqi Xu ,Florian
 Hahn ,Chen Zheng ,Jay Foad
 ,Daniel Grumberg ,Han-Kuan Chen
 ,Louis Dionne ,Louis Dionne
 ,Haojian Wu ,Simon Camphausen
 ,Longsheng Mou 
,Gleb
 Popov <6year...@gmail.com>,Jacek Caban ,Simon Pilgrim
 ,AinsleySnow <772571...@qq.com>,Louis Dionne
 ,Louis Dionne ,Florian Hahn
 ,Simon Pilgrim ,Daniel Chen
 ,Christian Ulmann ,Axel
 Lundberg <19574357+zonot...@users.noreply.github.com>,Dominik Adamski
 ,Simon Camphausen
 ,Florian Hahn ,Fanbo Meng
 ,Alexey Bataev ,aniplcc
 ,Simon Pilgrim ,Adrian Kuegel
 ,Simon Pilgrim ,Weining Lu
 ,David Spickett ,Paul
 Robinson ,Jay Foad ,
Amaury =?utf-8?q?Séchet?= ,Joe Nash
 ,Simon Pilgrim ,Mark
 de Wever ,Hsiangkai Wang ,Owen Pan
 ,Mark de Wever ,Chris Bieneman
 ,Nathan Chancellor ,Jonathan
 Peyton ,Krzysztof Pszeniczny
 ,Prashant Kumar ,Kazu Hirata
 ,Johannes Doerfert ,Alexey Bataev
 ,Slava Zakharin ,Vitaly Buka
 ,Vitaly Buka ,Aaron Ballman
 ,Michael Maitland ,maflcko
 <6399679+mafl...@users.noreply.github.com>,Alexey Bataev
 ,Rafael Ubal ,Louis Dionne
 ,Chenguang Wang ,Lei Wang
 ,Vitaly Buka ,David Green
 ,Lei Wang ,Alexey Bataev
 ,Simon Pilgrim ,David Green
 ,Changpeng Fang ,Joe Nash
 ,Kevin Frei ,Emma
 Pilkington ,Alexey Bataev 
 =?utf-8?q?,?=Alexey Bataev ,Christopher Di Bella
 ,Shourya Goel ,Alexey Bataev
 ,Simon Pilgrim ,Slava Zakharin
 ,Damien L-G ,Vitaly Buka
 ,Michael Maitland ,Michael
 Maitland ,Michael Maitland
 ,Michael Maitland 
,Michael
 Maitland ,Gulfem Savrun Yeniceri
 ,Kojo Acquah ,Kojo
 Acquah ,Dan Liew 
,Chelsea
 Cassanova ,Yeoul Na ,Jason
 Molenda ,Han-Chung Wang ,Craig
 Topper ,Shih-Po Hung ,Vitaly
 Buka ,darkbuck ,Craig Topper
 ,Matthias Springer ,Hristo Hristov
 ,Luke Lau ,Sourabh Singh Tomar
 ,Gulfem Savrun Yeniceri ,Luke
 Lau ,Kazu Hirata ,Daniil Kovalev
 ,Andreas Jonson ,Christian
 Ulmann ,Jan Patrick Lehr 
 =?utf-8?q?,?=Matthias Springer ,Haojian Wu
 ,Kadir Cetinkaya ,Matthias
 Springer ,Guillaume Chatelet ,Vyacheslav
 Levytskyy ,Guillaume Chatelet
 ,Fraser Cormack ,Jay Foad
 ,Stephen Tozer ,Tim Northover
 ,Daniil Kovalev ,Guillaume
 Chatelet ,Tom Eccles ,Stephen
 Tozer ,Ramkumar Ramachandra 
 =?utf-8?q?,?=Tom Eccles ,Simon Pilgrim
 ,jeanPerier ,"Andrew V. Teylu"
 ,Simon Pilgrim ,Tom Eccles
 ,Tom Eccles ,Simon Pilgrim
 ,Zahira Ammarguellat 
,Philip
 Lassen ,Luke Lau ,Florian Hahn
 ,Guillaume Chatelet ,Simon Pilgrim
 ,Simon Pilgrim ,Simon
 Pilgrim ,Victor Campos 
,OverMighty
 ,Jacek Caban ,Mehdi Amini
 ,Yitzhak Mandelbaum ,
Andrzej =?utf-8?q?Warzyński?= ,Jacek Caban
 ,Christian Ulmann ,Mikael
 Holmen ,Phoebe Wang 
,jeanPerier
 ,YunQiang Su ,Simon Pilgrim
 ,Simon Pilgrim ,Simon
 Pilgrim ,Simon Pilgrim ,Simon
 Pilgrim ,Simon Pilgrim ,Cyndy
 Ishida ,Piotr Sobczak ,Craig
 Topper ,Jay Foad ,Mark de Wever
 ,Simon Pilgrim ,Andrzej Warzynski
 ,lntue 
<35648136+ln...@users.noreply.github.com>,Simon
 Pilgrim ,Jay Foad ,Fangrui Song
 ,Fangrui Song ,Gulfem Savrun Yeniceri
 ,Julian Nagele ,Arthur Eubanks
 ,Fraser Cormack ,Mark de Wever
 ,Arthur Eubanks ,Arthur Eubanks
 ,Arthur Eubanks ,Arthur Eubanks
 ,Kazu Hirata ,Fangrui Song
 ,Fabian Mora ,Noah Goldstein
 ,Noah Goldstein ,Noah
 Goldstein ,Noah Goldstein 
,Cyndy
 Ishida ,Daniil Kovalev 
,Simon
 Pilgrim ,Eli Friedman ,Alexey
 Bataev ,Joseph Huber ,Kevin Frei
 ,Mark de Wever ,Jonathan
 Peyton ,Alexey Bataev 
,Vitaly
 Buka ,Vitaly Buka ,Florian
 Mayer ,Keyi Zhang ,Vitaly
 Buka ,Jeff Niu ,
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Vitaly Buka
 ,Florian Mayer ,Ian Anderson
 ,Victor Campos ,Kazu Hirata
 ,MaheshRavishankar
 <1663364+maheshravishan...@users.noreply.github.com>,Nikolas Klauser
 ,Slava Zakharin ,Vitaly Buka
 ,Michael Jones ,Chenguang Wang
 ,Vitaly Buka ,Vitaly Buka
 ,Koakuma ,Vitaly Buka
 ,Michael Kruse ,Keith
 Smiley ,Paul Kirth ,Alexey
 Bataev ,Shubham Rastogi
 ,Vitaly Buka 
,Craig
 Topper ,Shilei Tian ,Vitaly Buka
 ,Qizhi Hu <836744...@qq.com>,Youngsuk Kim
 ,Vitaly Buka ,Owen Pan
 ,Keith Smiley ,Farzon Lotfi
 <1802579+farz...@users.noreply.github.com>,Youngsuk Kim
 ,Congcong Cai ,Younan Zhang
 ,Matthias Springer ,Matthias Springer
 ,Vitaly Buka ,Matthias Springer
 ,Cyndy Ishida ,Christian Ulmann
 ,Christian Ulmann ,Qizhi
 Hu <836744...@qq.com>,mlevesquedion ,David
 Spickett ,David Spickett
 ,David Spickett ,Andrzej
 Warzynski ,AtariDreams 
,NagyDonat
 ,NagyDonat ,Mitch Phillips
 ,Benjamin Maxwell ,Mehdi Amini
 ,Mehdi Amini

[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

vitalybuka wrote:

@MaskRay @nikic  @efriedma-quic  Any comments?

https://github.com/llvm/llvm-project/pull/87568
___
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] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic commented:

This looks very reasonable to me, but I'm not a clang reviewer...

https://github.com/llvm/llvm-project/pull/87568
___
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] [Analysis] Exclude llvm.allow.{runtime, ubsan}.check() from AliasSetTracker (PR #86065)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/86065

>From f9cb87f89f2c2d4b17de4a4609ead16335102cf1 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Sun, 31 Mar 2024 22:45:20 -0700
Subject: [PATCH 1/2] rebase

Created using spr 1.3.4
---
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp 
b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 47e980e05281fc..0a3801bf965ff9 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallSet.h"
+
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Analysis/AssumptionCache.h"

>From abc4c2f5049ef74720e8fd9f056791d54026466c Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Sun, 31 Mar 2024 22:46:55 -0700
Subject: [PATCH 2/2] rebase

Created using spr 1.3.4
---
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp 
b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 0a3801bf965ff9..47e980e05281fc 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -14,7 +14,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallSet.h"
-
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Analysis/AssumptionCache.h"

___
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] [llvm] [InstCombiner] Remove trivially dead `llvm.allow.{runtime, ubsan}.check()` (PR #84851)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/84851

>From c15aa098b7a8db614f574d47c220852674d4681d Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Mon, 11 Mar 2024 17:13:07 -0700
Subject: [PATCH 1/2] rebase

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp |  6 +-
 clang/lib/CodeGen/CGExpr.cpp  | 15 +---
 clang/test/CodeGen/remote-traps.c | 23 +
 .../Instrumentation/RemoveTrapsPass.cpp   | 26 +++---
 .../Transforms/RemoveTraps/remove-traps.ll| 89 ++-
 5 files changed, 43 insertions(+), 116 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7e53469a48d42c..82b30b8d815629 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -100,9 +100,9 @@ using namespace llvm;
 namespace llvm {
 extern cl::opt PrintPipelinePasses;
 
-static cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
-   cl::desc("Insert remove-traps pass."),
-   cl::init(false));
+cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
+cl::desc("Insert remove-traps pass."),
+cl::init(false));
 
 // Experiment to move sanitizers earlier.
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 3a27622f165995..59a7fe8925001c 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -56,14 +56,7 @@ using namespace CodeGen;
 // Experiment to make sanitizers easier to debug
 static llvm::cl::opt ClSanitizeDebugDeoptimization(
 "ubsan-unique-traps", llvm::cl::Optional,
-llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check."),
-llvm::cl::init(false));
-
-// TODO: Introduce frontend options to enabled per sanitizers, similar to
-// `fsanitize-trap`.
-static llvm::cl::opt ClSanitizeExpHot(
-"ubsan-exp-hot", llvm::cl::Optional,
-llvm::cl::desc("Pass UBSAN checks if `llvm.experimental.hot()` is true."),
+llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check"),
 llvm::cl::init(false));
 
 //======//
@@ -3812,12 +3805,6 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
 SanitizerHandler CheckHandlerID) {
   llvm::BasicBlock *Cont = createBasicBlock("cont");
 
-  if (ClSanitizeExpHot) {
-Checked =
-Builder.CreateOr(Checked, Builder.CreateCall(CGM.getIntrinsic(
-  llvm::Intrinsic::experimental_hot)));
-  }
-
   // If we're optimizing, collapse all calls to trap down to just one per
   // check-type per function to save on code size.
   if ((int)TrapBBs.size() <= CheckHandlerID)
diff --git a/clang/test/CodeGen/remote-traps.c 
b/clang/test/CodeGen/remote-traps.c
index 16e4ebecb5c326..6751afb96d25f2 100644
--- a/clang/test/CodeGen/remote-traps.c
+++ b/clang/test/CodeGen/remote-traps.c
@@ -1,7 +1,5 @@
-// RUN: %clang_cc1 -O1 %s -o - -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -ubsan-exp-hot | FileCheck %s 
-// RUN: %clang_cc1 -O1 %s -o - -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -ubsan-exp-hot -mllvm 
-clang-remove-traps -mllvm -remove-traps-random-rate=1 %s -o - | FileCheck %s 
--check-prefixes=REMOVE
-
-#include 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow %s -o - | FileCheck %s 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -clang-remove-traps -mllvm 
-remove-traps-random-rate=1 %s -o - | FileCheck %s --implicit-check-not="call 
void @llvm.ubsantrap" --check-prefixes=REMOVE
 
 int test(int x) {
   return x + 123;
@@ -14,19 +12,4 @@ int test(int x) {
 // CHECK-NEXT: unreachable
 
 // REMOVE-LABEL: define {{.*}}i32 @test(
-// REMOVE: add i32 %x, 123
-// REMOVE-NEXT: ret i32
-
-
-bool experimental_hot() __asm("llvm.experimental.hot");
-
-bool test_asm() {
-  return experimental_hot();
-}
-
-// CHECK-LABEL: define {{.*}}i1 @test_asm(
-// CHECK: [[R:%.*]] = tail call zeroext i1 @llvm.experimental.hot()
-// CHECK: ret i1 [[R]]
-
-// REMOVE-LABEL: define {{.*}}i1 @test_asm(
-// REMOVE: ret i1 true
+// REMOVE: call { i32, i1 } @llvm.sadd.with.overflow.i32(
diff --git a/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp 
b/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
index fa4716f2e7a403..d87f7482a21d25 100644
--- a/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
+++ b/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
@@ -11,7 +11,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/ProfileSummaryInfo.h"
-#include "l

[llvm-branch-commits] [clang] [clang][builtin] Implement __builtin_allow_runtime_check (PR #87568)

2024-04-29 Thread Thurston Dang via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/87568
___
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] [CodeGen] Add default lowering for llvm.allow.{runtime, ubsan}.check() (PR #86049)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/86049

>From d44531592108a483e537e23ee650713e12e1f919 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Thu, 21 Mar 2024 11:09:50 -0700
Subject: [PATCH] unsaved aarch64

Created using spr 1.3.4
---
 llvm/test/CodeGen/AArch64/allow-check.ll | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/test/CodeGen/AArch64/allow-check.ll 
b/llvm/test/CodeGen/AArch64/allow-check.ll
index c315b216e222c0..9e4a47357906c6 100644
--- a/llvm/test/CodeGen/AArch64/allow-check.ll
+++ b/llvm/test/CodeGen/AArch64/allow-check.ll
@@ -1,7 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
-; RUN: llc < %s -mtriple=aarch64 | FileCheck %s
-; RUN: llc < %s -mtriple=aarch64 -global-isel | FileCheck %s
-; RUN: llc < %s -mtriple=aarch64 -fast-isel | FileCheck %s
+; RUN: llc < %s -mtriple=aarch64 -global-isel=0 -fast-isel=0 | FileCheck %s
+; RUN: llc < %s -mtriple=aarch64 -global-isel=1 -fast-isel=0 | FileCheck %s
+; RUN: llc < %s -mtriple=aarch64 -global-isel=0 -fast-isel=1 | FileCheck %s
 
 target triple = "aarch64-linux"
 

___
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] [Analysis] Exclude llvm.allow.{runtime, ubsan}.check() from AliasSetTracker (PR #86065)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/86065

>From f9cb87f89f2c2d4b17de4a4609ead16335102cf1 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Sun, 31 Mar 2024 22:45:20 -0700
Subject: [PATCH] rebase

Created using spr 1.3.4
---
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp 
b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 47e980e05281fc..0a3801bf965ff9 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallSet.h"
+
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Analysis/AssumptionCache.h"

___
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] [CodeGen] Add default lowering for llvm.allow.{runtime, ubsan}.check() (PR #86049)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/86049

>From d44531592108a483e537e23ee650713e12e1f919 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Thu, 21 Mar 2024 11:09:50 -0700
Subject: [PATCH] unsaved aarch64

Created using spr 1.3.4
---
 llvm/test/CodeGen/AArch64/allow-check.ll | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/test/CodeGen/AArch64/allow-check.ll 
b/llvm/test/CodeGen/AArch64/allow-check.ll
index c315b216e222c0..9e4a47357906c6 100644
--- a/llvm/test/CodeGen/AArch64/allow-check.ll
+++ b/llvm/test/CodeGen/AArch64/allow-check.ll
@@ -1,7 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
-; RUN: llc < %s -mtriple=aarch64 | FileCheck %s
-; RUN: llc < %s -mtriple=aarch64 -global-isel | FileCheck %s
-; RUN: llc < %s -mtriple=aarch64 -fast-isel | FileCheck %s
+; RUN: llc < %s -mtriple=aarch64 -global-isel=0 -fast-isel=0 | FileCheck %s
+; RUN: llc < %s -mtriple=aarch64 -global-isel=1 -fast-isel=0 | FileCheck %s
+; RUN: llc < %s -mtriple=aarch64 -global-isel=0 -fast-isel=1 | FileCheck %s
 
 target triple = "aarch64-linux"
 

___
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] [llvm] [InstCombiner] Remove unused `llvm.experimental.hot()` (PR #84851)

2024-04-29 Thread Jon Roelofs via llvm-branch-commits


@@ -56,7 +56,14 @@ using namespace CodeGen;
 // Experiment to make sanitizers easier to debug
 static llvm::cl::opt ClSanitizeDebugDeoptimization(
 "ubsan-unique-traps", llvm::cl::Optional,
-llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check"),
+llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check."),
+llvm::cl::init(false));
+
+// TODO: Introduce frontend options to enabled per sanitizers, similar to
+// `fsanitize-trap`.
+static llvm::cl::opt ClSanitizeExpHot(
+"ubsan-exp-hot", llvm::cl::Optional,
+llvm::cl::desc("Pass UBSAN checks if `llvm.experimental.hot()` is true."),

jroelofs wrote:

moved here: https://github.com/llvm/llvm-project/pull/84858/files#r1520603139

https://github.com/llvm/llvm-project/pull/84851
___
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] [llvm] [InstCombiner] Remove unused `llvm.experimental.hot()` (PR #84851)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/84851

>From c15aa098b7a8db614f574d47c220852674d4681d Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Mon, 11 Mar 2024 17:13:07 -0700
Subject: [PATCH] rebase

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp |  6 +-
 clang/lib/CodeGen/CGExpr.cpp  | 15 +---
 clang/test/CodeGen/remote-traps.c | 23 +
 .../Instrumentation/RemoveTrapsPass.cpp   | 26 +++---
 .../Transforms/RemoveTraps/remove-traps.ll| 89 ++-
 5 files changed, 43 insertions(+), 116 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7e53469a48d42c..82b30b8d815629 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -100,9 +100,9 @@ using namespace llvm;
 namespace llvm {
 extern cl::opt PrintPipelinePasses;
 
-static cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
-   cl::desc("Insert remove-traps pass."),
-   cl::init(false));
+cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
+cl::desc("Insert remove-traps pass."),
+cl::init(false));
 
 // Experiment to move sanitizers earlier.
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 3a27622f165995..59a7fe8925001c 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -56,14 +56,7 @@ using namespace CodeGen;
 // Experiment to make sanitizers easier to debug
 static llvm::cl::opt ClSanitizeDebugDeoptimization(
 "ubsan-unique-traps", llvm::cl::Optional,
-llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check."),
-llvm::cl::init(false));
-
-// TODO: Introduce frontend options to enabled per sanitizers, similar to
-// `fsanitize-trap`.
-static llvm::cl::opt ClSanitizeExpHot(
-"ubsan-exp-hot", llvm::cl::Optional,
-llvm::cl::desc("Pass UBSAN checks if `llvm.experimental.hot()` is true."),
+llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check"),
 llvm::cl::init(false));
 
 //======//
@@ -3812,12 +3805,6 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
 SanitizerHandler CheckHandlerID) {
   llvm::BasicBlock *Cont = createBasicBlock("cont");
 
-  if (ClSanitizeExpHot) {
-Checked =
-Builder.CreateOr(Checked, Builder.CreateCall(CGM.getIntrinsic(
-  llvm::Intrinsic::experimental_hot)));
-  }
-
   // If we're optimizing, collapse all calls to trap down to just one per
   // check-type per function to save on code size.
   if ((int)TrapBBs.size() <= CheckHandlerID)
diff --git a/clang/test/CodeGen/remote-traps.c 
b/clang/test/CodeGen/remote-traps.c
index 16e4ebecb5c326..6751afb96d25f2 100644
--- a/clang/test/CodeGen/remote-traps.c
+++ b/clang/test/CodeGen/remote-traps.c
@@ -1,7 +1,5 @@
-// RUN: %clang_cc1 -O1 %s -o - -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -ubsan-exp-hot | FileCheck %s 
-// RUN: %clang_cc1 -O1 %s -o - -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -ubsan-exp-hot -mllvm 
-clang-remove-traps -mllvm -remove-traps-random-rate=1 %s -o - | FileCheck %s 
--check-prefixes=REMOVE
-
-#include 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow %s -o - | FileCheck %s 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -clang-remove-traps -mllvm 
-remove-traps-random-rate=1 %s -o - | FileCheck %s --implicit-check-not="call 
void @llvm.ubsantrap" --check-prefixes=REMOVE
 
 int test(int x) {
   return x + 123;
@@ -14,19 +12,4 @@ int test(int x) {
 // CHECK-NEXT: unreachable
 
 // REMOVE-LABEL: define {{.*}}i32 @test(
-// REMOVE: add i32 %x, 123
-// REMOVE-NEXT: ret i32
-
-
-bool experimental_hot() __asm("llvm.experimental.hot");
-
-bool test_asm() {
-  return experimental_hot();
-}
-
-// CHECK-LABEL: define {{.*}}i1 @test_asm(
-// CHECK: [[R:%.*]] = tail call zeroext i1 @llvm.experimental.hot()
-// CHECK: ret i1 [[R]]
-
-// REMOVE-LABEL: define {{.*}}i1 @test_asm(
-// REMOVE: ret i1 true
+// REMOVE: call { i32, i1 } @llvm.sadd.with.overflow.i32(
diff --git a/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp 
b/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
index fa4716f2e7a403..d87f7482a21d25 100644
--- a/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
+++ b/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
@@ -11,7 +11,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/ProfileSummaryInfo.h"
-#include "llvm/

[llvm-branch-commits] [clang] [llvm] [InstCombiner] Remove trivially dead `llvm.allow.{runtime, ubsan}.check()` (PR #84851)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/84851

>From c15aa098b7a8db614f574d47c220852674d4681d Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Mon, 11 Mar 2024 17:13:07 -0700
Subject: [PATCH] rebase

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp |  6 +-
 clang/lib/CodeGen/CGExpr.cpp  | 15 +---
 clang/test/CodeGen/remote-traps.c | 23 +
 .../Instrumentation/RemoveTrapsPass.cpp   | 26 +++---
 .../Transforms/RemoveTraps/remove-traps.ll| 89 ++-
 5 files changed, 43 insertions(+), 116 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7e53469a48d42c..82b30b8d815629 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -100,9 +100,9 @@ using namespace llvm;
 namespace llvm {
 extern cl::opt PrintPipelinePasses;
 
-static cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
-   cl::desc("Insert remove-traps pass."),
-   cl::init(false));
+cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
+cl::desc("Insert remove-traps pass."),
+cl::init(false));
 
 // Experiment to move sanitizers earlier.
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 3a27622f165995..59a7fe8925001c 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -56,14 +56,7 @@ using namespace CodeGen;
 // Experiment to make sanitizers easier to debug
 static llvm::cl::opt ClSanitizeDebugDeoptimization(
 "ubsan-unique-traps", llvm::cl::Optional,
-llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check."),
-llvm::cl::init(false));
-
-// TODO: Introduce frontend options to enabled per sanitizers, similar to
-// `fsanitize-trap`.
-static llvm::cl::opt ClSanitizeExpHot(
-"ubsan-exp-hot", llvm::cl::Optional,
-llvm::cl::desc("Pass UBSAN checks if `llvm.experimental.hot()` is true."),
+llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check"),
 llvm::cl::init(false));
 
 //======//
@@ -3812,12 +3805,6 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
 SanitizerHandler CheckHandlerID) {
   llvm::BasicBlock *Cont = createBasicBlock("cont");
 
-  if (ClSanitizeExpHot) {
-Checked =
-Builder.CreateOr(Checked, Builder.CreateCall(CGM.getIntrinsic(
-  llvm::Intrinsic::experimental_hot)));
-  }
-
   // If we're optimizing, collapse all calls to trap down to just one per
   // check-type per function to save on code size.
   if ((int)TrapBBs.size() <= CheckHandlerID)
diff --git a/clang/test/CodeGen/remote-traps.c 
b/clang/test/CodeGen/remote-traps.c
index 16e4ebecb5c326..6751afb96d25f2 100644
--- a/clang/test/CodeGen/remote-traps.c
+++ b/clang/test/CodeGen/remote-traps.c
@@ -1,7 +1,5 @@
-// RUN: %clang_cc1 -O1 %s -o - -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -ubsan-exp-hot | FileCheck %s 
-// RUN: %clang_cc1 -O1 %s -o - -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -ubsan-exp-hot -mllvm 
-clang-remove-traps -mllvm -remove-traps-random-rate=1 %s -o - | FileCheck %s 
--check-prefixes=REMOVE
-
-#include 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow %s -o - | FileCheck %s 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -clang-remove-traps -mllvm 
-remove-traps-random-rate=1 %s -o - | FileCheck %s --implicit-check-not="call 
void @llvm.ubsantrap" --check-prefixes=REMOVE
 
 int test(int x) {
   return x + 123;
@@ -14,19 +12,4 @@ int test(int x) {
 // CHECK-NEXT: unreachable
 
 // REMOVE-LABEL: define {{.*}}i32 @test(
-// REMOVE: add i32 %x, 123
-// REMOVE-NEXT: ret i32
-
-
-bool experimental_hot() __asm("llvm.experimental.hot");
-
-bool test_asm() {
-  return experimental_hot();
-}
-
-// CHECK-LABEL: define {{.*}}i1 @test_asm(
-// CHECK: [[R:%.*]] = tail call zeroext i1 @llvm.experimental.hot()
-// CHECK: ret i1 [[R]]
-
-// REMOVE-LABEL: define {{.*}}i1 @test_asm(
-// REMOVE: ret i1 true
+// REMOVE: call { i32, i1 } @llvm.sadd.with.overflow.i32(
diff --git a/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp 
b/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
index fa4716f2e7a403..d87f7482a21d25 100644
--- a/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
+++ b/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
@@ -11,7 +11,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/ProfileSummaryInfo.h"
-#include "llvm/

[llvm-branch-commits] [clang] [llvm] [InstCombiner] Remove trivially dead `llvm.allow.{runtime, ubsan}.check()` (PR #84851)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/84851

>From c15aa098b7a8db614f574d47c220852674d4681d Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Mon, 11 Mar 2024 17:13:07 -0700
Subject: [PATCH 1/2] rebase

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp |  6 +-
 clang/lib/CodeGen/CGExpr.cpp  | 15 +---
 clang/test/CodeGen/remote-traps.c | 23 +
 .../Instrumentation/RemoveTrapsPass.cpp   | 26 +++---
 .../Transforms/RemoveTraps/remove-traps.ll| 89 ++-
 5 files changed, 43 insertions(+), 116 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7e53469a48d42c..82b30b8d815629 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -100,9 +100,9 @@ using namespace llvm;
 namespace llvm {
 extern cl::opt PrintPipelinePasses;
 
-static cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
-   cl::desc("Insert remove-traps pass."),
-   cl::init(false));
+cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
+cl::desc("Insert remove-traps pass."),
+cl::init(false));
 
 // Experiment to move sanitizers earlier.
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 3a27622f165995..59a7fe8925001c 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -56,14 +56,7 @@ using namespace CodeGen;
 // Experiment to make sanitizers easier to debug
 static llvm::cl::opt ClSanitizeDebugDeoptimization(
 "ubsan-unique-traps", llvm::cl::Optional,
-llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check."),
-llvm::cl::init(false));
-
-// TODO: Introduce frontend options to enabled per sanitizers, similar to
-// `fsanitize-trap`.
-static llvm::cl::opt ClSanitizeExpHot(
-"ubsan-exp-hot", llvm::cl::Optional,
-llvm::cl::desc("Pass UBSAN checks if `llvm.experimental.hot()` is true."),
+llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check"),
 llvm::cl::init(false));
 
 //======//
@@ -3812,12 +3805,6 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
 SanitizerHandler CheckHandlerID) {
   llvm::BasicBlock *Cont = createBasicBlock("cont");
 
-  if (ClSanitizeExpHot) {
-Checked =
-Builder.CreateOr(Checked, Builder.CreateCall(CGM.getIntrinsic(
-  llvm::Intrinsic::experimental_hot)));
-  }
-
   // If we're optimizing, collapse all calls to trap down to just one per
   // check-type per function to save on code size.
   if ((int)TrapBBs.size() <= CheckHandlerID)
diff --git a/clang/test/CodeGen/remote-traps.c 
b/clang/test/CodeGen/remote-traps.c
index 16e4ebecb5c326..6751afb96d25f2 100644
--- a/clang/test/CodeGen/remote-traps.c
+++ b/clang/test/CodeGen/remote-traps.c
@@ -1,7 +1,5 @@
-// RUN: %clang_cc1 -O1 %s -o - -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -ubsan-exp-hot | FileCheck %s 
-// RUN: %clang_cc1 -O1 %s -o - -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -ubsan-exp-hot -mllvm 
-clang-remove-traps -mllvm -remove-traps-random-rate=1 %s -o - | FileCheck %s 
--check-prefixes=REMOVE
-
-#include 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow %s -o - | FileCheck %s 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -clang-remove-traps -mllvm 
-remove-traps-random-rate=1 %s -o - | FileCheck %s --implicit-check-not="call 
void @llvm.ubsantrap" --check-prefixes=REMOVE
 
 int test(int x) {
   return x + 123;
@@ -14,19 +12,4 @@ int test(int x) {
 // CHECK-NEXT: unreachable
 
 // REMOVE-LABEL: define {{.*}}i32 @test(
-// REMOVE: add i32 %x, 123
-// REMOVE-NEXT: ret i32
-
-
-bool experimental_hot() __asm("llvm.experimental.hot");
-
-bool test_asm() {
-  return experimental_hot();
-}
-
-// CHECK-LABEL: define {{.*}}i1 @test_asm(
-// CHECK: [[R:%.*]] = tail call zeroext i1 @llvm.experimental.hot()
-// CHECK: ret i1 [[R]]
-
-// REMOVE-LABEL: define {{.*}}i1 @test_asm(
-// REMOVE: ret i1 true
+// REMOVE: call { i32, i1 } @llvm.sadd.with.overflow.i32(
diff --git a/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp 
b/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
index fa4716f2e7a403..d87f7482a21d25 100644
--- a/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
+++ b/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
@@ -11,7 +11,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/ProfileSummaryInfo.h"
-#include "l

[llvm-branch-commits] [llvm] [CodeGen] Add default lowering for llvm.allow.{runtime, ubsan}.check() (PR #86049)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/86049

>From d44531592108a483e537e23ee650713e12e1f919 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Thu, 21 Mar 2024 11:09:50 -0700
Subject: [PATCH] unsaved aarch64

Created using spr 1.3.4
---
 llvm/test/CodeGen/AArch64/allow-check.ll | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/test/CodeGen/AArch64/allow-check.ll 
b/llvm/test/CodeGen/AArch64/allow-check.ll
index c315b216e222c0..9e4a47357906c6 100644
--- a/llvm/test/CodeGen/AArch64/allow-check.ll
+++ b/llvm/test/CodeGen/AArch64/allow-check.ll
@@ -1,7 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
-; RUN: llc < %s -mtriple=aarch64 | FileCheck %s
-; RUN: llc < %s -mtriple=aarch64 -global-isel | FileCheck %s
-; RUN: llc < %s -mtriple=aarch64 -fast-isel | FileCheck %s
+; RUN: llc < %s -mtriple=aarch64 -global-isel=0 -fast-isel=0 | FileCheck %s
+; RUN: llc < %s -mtriple=aarch64 -global-isel=1 -fast-isel=0 | FileCheck %s
+; RUN: llc < %s -mtriple=aarch64 -global-isel=0 -fast-isel=1 | FileCheck %s
 
 target triple = "aarch64-linux"
 

___
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] [CodeGen] Add default lowering for llvm.allow.{runtime, ubsan}.check() (PR #86049)

2024-04-29 Thread Matt Arsenault via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/86049
___
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] [llvm] [InstCombiner] Remove trivially dead `llvm.allow.{runtime, ubsan}.check()` (PR #84851)

2024-04-29 Thread Vitaly Buka via llvm-branch-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/84851

>From c15aa098b7a8db614f574d47c220852674d4681d Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Mon, 11 Mar 2024 17:13:07 -0700
Subject: [PATCH] rebase

Created using spr 1.3.4
---
 clang/lib/CodeGen/BackendUtil.cpp |  6 +-
 clang/lib/CodeGen/CGExpr.cpp  | 15 +---
 clang/test/CodeGen/remote-traps.c | 23 +
 .../Instrumentation/RemoveTrapsPass.cpp   | 26 +++---
 .../Transforms/RemoveTraps/remove-traps.ll| 89 ++-
 5 files changed, 43 insertions(+), 116 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7e53469a48d42c..82b30b8d815629 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -100,9 +100,9 @@ using namespace llvm;
 namespace llvm {
 extern cl::opt PrintPipelinePasses;
 
-static cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
-   cl::desc("Insert remove-traps pass."),
-   cl::init(false));
+cl::opt ClRemoveTraps("clang-remove-traps", cl::Optional,
+cl::desc("Insert remove-traps pass."),
+cl::init(false));
 
 // Experiment to move sanitizers earlier.
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 3a27622f165995..59a7fe8925001c 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -56,14 +56,7 @@ using namespace CodeGen;
 // Experiment to make sanitizers easier to debug
 static llvm::cl::opt ClSanitizeDebugDeoptimization(
 "ubsan-unique-traps", llvm::cl::Optional,
-llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check."),
-llvm::cl::init(false));
-
-// TODO: Introduce frontend options to enabled per sanitizers, similar to
-// `fsanitize-trap`.
-static llvm::cl::opt ClSanitizeExpHot(
-"ubsan-exp-hot", llvm::cl::Optional,
-llvm::cl::desc("Pass UBSAN checks if `llvm.experimental.hot()` is true."),
+llvm::cl::desc("Deoptimize traps for UBSAN so there is 1 trap per check"),
 llvm::cl::init(false));
 
 //======//
@@ -3812,12 +3805,6 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
 SanitizerHandler CheckHandlerID) {
   llvm::BasicBlock *Cont = createBasicBlock("cont");
 
-  if (ClSanitizeExpHot) {
-Checked =
-Builder.CreateOr(Checked, Builder.CreateCall(CGM.getIntrinsic(
-  llvm::Intrinsic::experimental_hot)));
-  }
-
   // If we're optimizing, collapse all calls to trap down to just one per
   // check-type per function to save on code size.
   if ((int)TrapBBs.size() <= CheckHandlerID)
diff --git a/clang/test/CodeGen/remote-traps.c 
b/clang/test/CodeGen/remote-traps.c
index 16e4ebecb5c326..6751afb96d25f2 100644
--- a/clang/test/CodeGen/remote-traps.c
+++ b/clang/test/CodeGen/remote-traps.c
@@ -1,7 +1,5 @@
-// RUN: %clang_cc1 -O1 %s -o - -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -ubsan-exp-hot | FileCheck %s 
-// RUN: %clang_cc1 -O1 %s -o - -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -ubsan-exp-hot -mllvm 
-clang-remove-traps -mllvm -remove-traps-random-rate=1 %s -o - | FileCheck %s 
--check-prefixes=REMOVE
-
-#include 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow %s -o - | FileCheck %s 
+// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow 
-fsanitize-trap=signed-integer-overflow -mllvm -clang-remove-traps -mllvm 
-remove-traps-random-rate=1 %s -o - | FileCheck %s --implicit-check-not="call 
void @llvm.ubsantrap" --check-prefixes=REMOVE
 
 int test(int x) {
   return x + 123;
@@ -14,19 +12,4 @@ int test(int x) {
 // CHECK-NEXT: unreachable
 
 // REMOVE-LABEL: define {{.*}}i32 @test(
-// REMOVE: add i32 %x, 123
-// REMOVE-NEXT: ret i32
-
-
-bool experimental_hot() __asm("llvm.experimental.hot");
-
-bool test_asm() {
-  return experimental_hot();
-}
-
-// CHECK-LABEL: define {{.*}}i1 @test_asm(
-// CHECK: [[R:%.*]] = tail call zeroext i1 @llvm.experimental.hot()
-// CHECK: ret i1 [[R]]
-
-// REMOVE-LABEL: define {{.*}}i1 @test_asm(
-// REMOVE: ret i1 true
+// REMOVE: call { i32, i1 } @llvm.sadd.with.overflow.i32(
diff --git a/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp 
b/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
index fa4716f2e7a403..d87f7482a21d25 100644
--- a/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
+++ b/llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
@@ -11,7 +11,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/ProfileSummaryInfo.h"
-#include "llvm/

[llvm-branch-commits] [clang] [llvm] [InstCombiner] Remove trivially dead `llvm.allow.{runtime, ubsan}.check()` (PR #84851)

2024-04-29 Thread Nikita Popov via llvm-branch-commits

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

LGTM

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


  1   2   >