[llvm-branch-commits] [llvm] release/18.x: [GlobalISel] Don't form anyextending atomic loads. (PR #90435)

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

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

Backport 60fc4ac67a613e4e36cef019fb2d13d70a06cfe8

Requested by: @nikic

>From 00370f3fc3238b7516512c00956221ab9225a2bb Mon Sep 17 00:00:00 2001
From: Amara Emerson 
Date: Fri, 5 Apr 2024 10:49:19 -0700
Subject: [PATCH] [GlobalISel] Don't form anyextending atomic loads.

Until we can reliably check the legality and improve our selection of these,
don't form them at all.

(cherry picked from commit 60fc4ac67a613e4e36cef019fb2d13d70a06cfe8)
---
 .../lib/CodeGen/GlobalISel/CombinerHelper.cpp |  4 +-
 .../Atomics/aarch64-atomic-load-rcpc_immo.ll  | 55 +-
 .../AArch64/GlobalISel/arm64-atomic.ll| 56 +--
 .../AArch64/GlobalISel/arm64-pcsections.ll| 28 +-
 .../atomic-anyextending-load-crash.ll | 47 
 5 files changed, 131 insertions(+), 59 deletions(-)
 create mode 100644 
llvm/test/CodeGen/AArch64/GlobalISel/atomic-anyextending-load-crash.ll

diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp 
b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index 772229215e798d..61ddc858ba44c7 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -591,8 +591,8 @@ bool 
CombinerHelper::matchCombineExtendingLoads(MachineInstr &MI,
 UseMI.getOpcode() == TargetOpcode::G_ZEXT ||
 (UseMI.getOpcode() == TargetOpcode::G_ANYEXT)) {
   const auto &MMO = LoadMI->getMMO();
-  // For atomics, only form anyextending loads.
-  if (MMO.isAtomic() && UseMI.getOpcode() != TargetOpcode::G_ANYEXT)
+  // Don't do anything for atomics.
+  if (MMO.isAtomic())
 continue;
   // Check for legality.
   if (!isPreLegalize()) {
diff --git a/llvm/test/CodeGen/AArch64/Atomics/aarch64-atomic-load-rcpc_immo.ll 
b/llvm/test/CodeGen/AArch64/Atomics/aarch64-atomic-load-rcpc_immo.ll
index b0507e9d075fab..9687ba683fb7e6 100644
--- a/llvm/test/CodeGen/AArch64/Atomics/aarch64-atomic-load-rcpc_immo.ll
+++ b/llvm/test/CodeGen/AArch64/Atomics/aarch64-atomic-load-rcpc_immo.ll
@@ -35,16 +35,24 @@ define i8 @load_atomic_i8_aligned_monotonic_const(ptr 
readonly %ptr) {
 }
 
 define i8 @load_atomic_i8_aligned_acquire(ptr %ptr) {
-; CHECK-LABEL: load_atomic_i8_aligned_acquire:
-; CHECK:ldapurb w0, [x0, #4]
+; GISEL-LABEL: load_atomic_i8_aligned_acquire:
+; GISEL:add x8, x0, #4
+; GISEL:ldaprb w0, [x8]
+;
+; SDAG-LABEL: load_atomic_i8_aligned_acquire:
+; SDAG:ldapurb w0, [x0, #4]
 %gep = getelementptr inbounds i8, ptr %ptr, i32 4
 %r = load atomic i8, ptr %gep acquire, align 1
 ret i8 %r
 }
 
 define i8 @load_atomic_i8_aligned_acquire_const(ptr readonly %ptr) {
-; CHECK-LABEL: load_atomic_i8_aligned_acquire_const:
-; CHECK:ldapurb w0, [x0, #4]
+; GISEL-LABEL: load_atomic_i8_aligned_acquire_const:
+; GISEL:add x8, x0, #4
+; GISEL:ldaprb w0, [x8]
+;
+; SDAG-LABEL: load_atomic_i8_aligned_acquire_const:
+; SDAG:ldapurb w0, [x0, #4]
 %gep = getelementptr inbounds i8, ptr %ptr, i32 4
 %r = load atomic i8, ptr %gep acquire, align 1
 ret i8 %r
@@ -101,16 +109,24 @@ define i16 @load_atomic_i16_aligned_monotonic_const(ptr 
readonly %ptr) {
 }
 
 define i16 @load_atomic_i16_aligned_acquire(ptr %ptr) {
-; CHECK-LABEL: load_atomic_i16_aligned_acquire:
-; CHECK:ldapurh w0, [x0, #8]
+; GISEL-LABEL: load_atomic_i16_aligned_acquire:
+; GISEL:add x8, x0, #8
+; GISEL:ldaprh w0, [x8]
+;
+; SDAG-LABEL: load_atomic_i16_aligned_acquire:
+; SDAG:ldapurh w0, [x0, #8]
 %gep = getelementptr inbounds i16, ptr %ptr, i32 4
 %r = load atomic i16, ptr %gep acquire, align 2
 ret i16 %r
 }
 
 define i16 @load_atomic_i16_aligned_acquire_const(ptr readonly %ptr) {
-; CHECK-LABEL: load_atomic_i16_aligned_acquire_const:
-; CHECK:ldapurh w0, [x0, #8]
+; GISEL-LABEL: load_atomic_i16_aligned_acquire_const:
+; GISEL:add x8, x0, #8
+; GISEL:ldaprh w0, [x8]
+;
+; SDAG-LABEL: load_atomic_i16_aligned_acquire_const:
+; SDAG:ldapurh w0, [x0, #8]
 %gep = getelementptr inbounds i16, ptr %ptr, i32 4
 %r = load atomic i16, ptr %gep acquire, align 2
 ret i16 %r
@@ -367,16 +383,24 @@ define i8 @load_atomic_i8_unaligned_monotonic_const(ptr 
readonly %ptr) {
 }
 
 define i8 @load_atomic_i8_unaligned_acquire(ptr %ptr) {
-; CHECK-LABEL: load_atomic_i8_unaligned_acquire:
-; CHECK:ldapurb w0, [x0, #4]
+; GISEL-LABEL: load_atomic_i8_unaligned_acquire:
+; GISEL:add x8, x0, #4
+; GISEL:ldaprb w0, [x8]
+;
+; SDAG-LABEL: load_atomic_i8_unaligned_acquire:
+; SDAG:ldapurb w0, [x0, #4]
 %gep = getelementptr inbounds i8, ptr %ptr, i32 4
 %r = load atomic i8, ptr %gep acquire, align 1
 ret i8 %r
 }
 
 define i8 @load_atomic_i8_unaligned_acquire_const(ptr readonly %ptr) {
-; CHECK-LABEL: load_atomic_i8_unaligned_acquire_const:
-; CHECK:ldapurb w0, [x0, #4]
+; GISEL-LABEL: load_atomic_i8_unaligned_acquire_const:
+; GISEL:add

[llvm-branch-commits] [llvm] release/18.x: [GlobalISel] Don't form anyextending atomic loads. (PR #90435)

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

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/90435
___
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: [GlobalISel] Don't form anyextending atomic loads. (PR #90435)

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

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: None (llvmbot)


Changes

Backport 60fc4ac67a613e4e36cef019fb2d13d70a06cfe8

Requested by: @nikic

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


5 Files Affected:

- (modified) llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp (+2-2) 
- (modified) llvm/test/CodeGen/AArch64/Atomics/aarch64-atomic-load-rcpc_immo.ll 
(+40-15) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/arm64-atomic.ll (+28-28) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/arm64-pcsections.ll (+14-14) 
- (added) 
llvm/test/CodeGen/AArch64/GlobalISel/atomic-anyextending-load-crash.ll (+47) 


``diff
diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp 
b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index 772229215e798d..61ddc858ba44c7 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -591,8 +591,8 @@ bool 
CombinerHelper::matchCombineExtendingLoads(MachineInstr &MI,
 UseMI.getOpcode() == TargetOpcode::G_ZEXT ||
 (UseMI.getOpcode() == TargetOpcode::G_ANYEXT)) {
   const auto &MMO = LoadMI->getMMO();
-  // For atomics, only form anyextending loads.
-  if (MMO.isAtomic() && UseMI.getOpcode() != TargetOpcode::G_ANYEXT)
+  // Don't do anything for atomics.
+  if (MMO.isAtomic())
 continue;
   // Check for legality.
   if (!isPreLegalize()) {
diff --git a/llvm/test/CodeGen/AArch64/Atomics/aarch64-atomic-load-rcpc_immo.ll 
b/llvm/test/CodeGen/AArch64/Atomics/aarch64-atomic-load-rcpc_immo.ll
index b0507e9d075fab..9687ba683fb7e6 100644
--- a/llvm/test/CodeGen/AArch64/Atomics/aarch64-atomic-load-rcpc_immo.ll
+++ b/llvm/test/CodeGen/AArch64/Atomics/aarch64-atomic-load-rcpc_immo.ll
@@ -35,16 +35,24 @@ define i8 @load_atomic_i8_aligned_monotonic_const(ptr 
readonly %ptr) {
 }
 
 define i8 @load_atomic_i8_aligned_acquire(ptr %ptr) {
-; CHECK-LABEL: load_atomic_i8_aligned_acquire:
-; CHECK:ldapurb w0, [x0, #4]
+; GISEL-LABEL: load_atomic_i8_aligned_acquire:
+; GISEL:add x8, x0, #4
+; GISEL:ldaprb w0, [x8]
+;
+; SDAG-LABEL: load_atomic_i8_aligned_acquire:
+; SDAG:ldapurb w0, [x0, #4]
 %gep = getelementptr inbounds i8, ptr %ptr, i32 4
 %r = load atomic i8, ptr %gep acquire, align 1
 ret i8 %r
 }
 
 define i8 @load_atomic_i8_aligned_acquire_const(ptr readonly %ptr) {
-; CHECK-LABEL: load_atomic_i8_aligned_acquire_const:
-; CHECK:ldapurb w0, [x0, #4]
+; GISEL-LABEL: load_atomic_i8_aligned_acquire_const:
+; GISEL:add x8, x0, #4
+; GISEL:ldaprb w0, [x8]
+;
+; SDAG-LABEL: load_atomic_i8_aligned_acquire_const:
+; SDAG:ldapurb w0, [x0, #4]
 %gep = getelementptr inbounds i8, ptr %ptr, i32 4
 %r = load atomic i8, ptr %gep acquire, align 1
 ret i8 %r
@@ -101,16 +109,24 @@ define i16 @load_atomic_i16_aligned_monotonic_const(ptr 
readonly %ptr) {
 }
 
 define i16 @load_atomic_i16_aligned_acquire(ptr %ptr) {
-; CHECK-LABEL: load_atomic_i16_aligned_acquire:
-; CHECK:ldapurh w0, [x0, #8]
+; GISEL-LABEL: load_atomic_i16_aligned_acquire:
+; GISEL:add x8, x0, #8
+; GISEL:ldaprh w0, [x8]
+;
+; SDAG-LABEL: load_atomic_i16_aligned_acquire:
+; SDAG:ldapurh w0, [x0, #8]
 %gep = getelementptr inbounds i16, ptr %ptr, i32 4
 %r = load atomic i16, ptr %gep acquire, align 2
 ret i16 %r
 }
 
 define i16 @load_atomic_i16_aligned_acquire_const(ptr readonly %ptr) {
-; CHECK-LABEL: load_atomic_i16_aligned_acquire_const:
-; CHECK:ldapurh w0, [x0, #8]
+; GISEL-LABEL: load_atomic_i16_aligned_acquire_const:
+; GISEL:add x8, x0, #8
+; GISEL:ldaprh w0, [x8]
+;
+; SDAG-LABEL: load_atomic_i16_aligned_acquire_const:
+; SDAG:ldapurh w0, [x0, #8]
 %gep = getelementptr inbounds i16, ptr %ptr, i32 4
 %r = load atomic i16, ptr %gep acquire, align 2
 ret i16 %r
@@ -367,16 +383,24 @@ define i8 @load_atomic_i8_unaligned_monotonic_const(ptr 
readonly %ptr) {
 }
 
 define i8 @load_atomic_i8_unaligned_acquire(ptr %ptr) {
-; CHECK-LABEL: load_atomic_i8_unaligned_acquire:
-; CHECK:ldapurb w0, [x0, #4]
+; GISEL-LABEL: load_atomic_i8_unaligned_acquire:
+; GISEL:add x8, x0, #4
+; GISEL:ldaprb w0, [x8]
+;
+; SDAG-LABEL: load_atomic_i8_unaligned_acquire:
+; SDAG:ldapurb w0, [x0, #4]
 %gep = getelementptr inbounds i8, ptr %ptr, i32 4
 %r = load atomic i8, ptr %gep acquire, align 1
 ret i8 %r
 }
 
 define i8 @load_atomic_i8_unaligned_acquire_const(ptr readonly %ptr) {
-; CHECK-LABEL: load_atomic_i8_unaligned_acquire_const:
-; CHECK:ldapurb w0, [x0, #4]
+; GISEL-LABEL: load_atomic_i8_unaligned_acquire_const:
+; GISEL:add x8, x0, #4
+; GISEL:ldaprb w0, [x8]
+;
+; SDAG-LABEL: load_atomic_i8_unaligned_acquire_const:
+; SDAG:ldapurb w0, [x0, #4]
 %gep = getelementptr inbounds i8, ptr %ptr, i32 4
 %r = load atomic i8, ptr %gep acquire, align 1
 ret i8 %r
@@ -819,7 +843,8 @@ define i128 @load_atomic_i128_unaligned_seq_cst_const(ptr 
r

[llvm-branch-commits] [llvm] release/18.x: [CGP] Drop poison-generating flags after hoisting (#90382) (PR #90437)

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

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/90437
___
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: [CGP] Drop poison-generating flags after hoisting (#90382) (PR #90437)

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

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

Backport ab12bba0aad800c1805eca2ea937da958c1854c8

Requested by: @dtcxzyw

>From 237863e781eb5d8f1562faea28db90fbf050e43f Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Mon, 29 Apr 2024 15:51:49 +0800
Subject: [PATCH]  [CGP] Drop poison-generating flags after hoisting (#90382)

See the following case:
```
define i8 @src1(i8 %x) {
entry:
  %cmp = icmp eq i8 %x, -1
  br i1 %cmp, label %exit, label %if.then

if.then:
  %inc = add nuw nsw i8 %x, 1
  br label %exit

exit:
  %retval = phi i8 [ %inc, %if.then ], [ -1, %entry ]
  ret i8 %retval
}

define i8 @tgt1(i8 %x) {
entry:
  %inc = add nuw nsw i8 %x, 1
  %0 = icmp eq i8 %inc, 0
  br i1 %0, label %exit, label %if.then

if.then:  ; preds = %entry
  br label %exit

exit: ; preds = %if.then, %entry
  %retval = phi i8 [ %inc, %if.then ], [ -1, %entry ]
  ret i8 %retval
}
```
`optimizeBranch` converts `icmp eq X, -1` into cmp to zero on RISC-V and
hoists the add into the entry block. Poison-generating flags should be
dropped as they don't still hold.

Proof: https://alive2.llvm.org/ce/z/sP7mvK
Fixes https://github.com/llvm/llvm-project/issues/90380

(cherry picked from commit ab12bba0aad800c1805eca2ea937da958c1854c8)
---
 llvm/lib/CodeGen/CodeGenPrepare.cpp   |  2 +
 .../CodeGenPrepare/ARM/branch-on-zero.ll  | 23 ++
 .../CodeGenPrepare/RISCV/convert-to-eqz.ll| 80 +++
 3 files changed, 105 insertions(+)
 create mode 100644 llvm/test/Transforms/CodeGenPrepare/RISCV/convert-to-eqz.ll

diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp 
b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 8ee1f19e083e4e..1cca56fc19cfd8 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -8154,6 +8154,7 @@ static bool optimizeBranch(BranchInst *Branch, const 
TargetLowering &TLI,
   IRBuilder<> Builder(Branch);
   if (UI->getParent() != Branch->getParent())
 UI->moveBefore(Branch);
+  UI->dropPoisonGeneratingFlags();
   Value *NewCmp = Builder.CreateCmp(ICmpInst::ICMP_EQ, UI,
 ConstantInt::get(UI->getType(), 0));
   LLVM_DEBUG(dbgs() << "Converting " << *Cmp << "\n");
@@ -8167,6 +8168,7 @@ static bool optimizeBranch(BranchInst *Branch, const 
TargetLowering &TLI,
   IRBuilder<> Builder(Branch);
   if (UI->getParent() != Branch->getParent())
 UI->moveBefore(Branch);
+  UI->dropPoisonGeneratingFlags();
   Value *NewCmp = Builder.CreateCmp(Cmp->getPredicate(), UI,
 ConstantInt::get(UI->getType(), 0));
   LLVM_DEBUG(dbgs() << "Converting " << *Cmp << "\n");
diff --git a/llvm/test/Transforms/CodeGenPrepare/ARM/branch-on-zero.ll 
b/llvm/test/Transforms/CodeGenPrepare/ARM/branch-on-zero.ll
index ff5cef7e781fe6..25dfb3c53a077b 100644
--- a/llvm/test/Transforms/CodeGenPrepare/ARM/branch-on-zero.ll
+++ b/llvm/test/Transforms/CodeGenPrepare/ARM/branch-on-zero.ll
@@ -211,6 +211,29 @@ else:
   ret i32 %l
 }
 
+define i32 @sub10_else_drop_nuw(i32 %a) {
+; CHECK-LABEL: @sub10_else_drop_nuw(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[L:%.*]] = sub i32 [[A:%.*]], 10
+; CHECK-NEXT:[[TMP0:%.*]] = icmp eq i32 [[L]], 0
+; CHECK-NEXT:br i1 [[TMP0]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK:   then:
+; CHECK-NEXT:ret i32 0
+; CHECK:   else:
+; CHECK-NEXT:ret i32 [[L]]
+;
+entry:
+  %c = icmp eq i32 %a, 10
+  br i1 %c, label %then, label %else
+
+then:
+  ret i32 0
+
+else:
+  %l = sub nuw i32 %a, 10
+  ret i32 %l
+}
+
 define i32 @subm10_then(i32 %a) {
 ; CHECK-LABEL: @subm10_then(
 ; CHECK-NEXT:  entry:
diff --git a/llvm/test/Transforms/CodeGenPrepare/RISCV/convert-to-eqz.ll 
b/llvm/test/Transforms/CodeGenPrepare/RISCV/convert-to-eqz.ll
new file mode 100644
index 00..a6909d14913494
--- /dev/null
+++ b/llvm/test/Transforms/CodeGenPrepare/RISCV/convert-to-eqz.ll
@@ -0,0 +1,80 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 4
+; RUN: opt -codegenprepare -S -mtriple=riscv64 < %s | FileCheck %s
+
+define i8 @hoist_add(i8 %x) {
+; CHECK-LABEL: define i8 @hoist_add(
+; CHECK-SAME: i8 [[X:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[INC:%.*]] = add i8 [[X]], 1
+; CHECK-NEXT:[[TMP0:%.*]] = icmp eq i8 [[INC]], 0
+; CHECK-NEXT:br i1 [[TMP0]], label [[EXIT:%.*]], label [[IF_THEN:%.*]]
+; CHECK:   if.then:
+; CHECK-NEXT:br label [[EXIT]]
+; CHECK:   exit:
+; CHECK-NEXT:[[RETVAL:%.*]] = phi i8 [ [[INC]], [[IF_THEN]] ], [ -1, 
[[ENTRY:%.*]] ]
+; CHECK-NEXT:ret i8 [[RETVAL]]
+;
+entry:
+  %cmp = icmp eq i8 %x, -1
+  br i1 %cmp, label %exit, label %if.then
+
+if.then:
+  %inc = add nuw nsw i8 %x, 1
+  br label %exit
+
+exit:
+  %retval = phi i8 [ %inc, %if.then ], [ -1, %entry ]
+  ret i8 %retval
+}
+
+define i8 @hoist_lshr(i8

[llvm-branch-commits] [llvm] release/18.x: [CGP] Drop poison-generating flags after hoisting (#90382) (PR #90437)

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

llvmbot wrote:

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

https://github.com/llvm/llvm-project/pull/90437
___
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: [CGP] Drop poison-generating flags after hoisting (#90382) (PR #90437)

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

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: None (llvmbot)


Changes

Backport ab12bba0aad800c1805eca2ea937da958c1854c8

Requested by: @dtcxzyw

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


3 Files Affected:

- (modified) llvm/lib/CodeGen/CodeGenPrepare.cpp (+2) 
- (modified) llvm/test/Transforms/CodeGenPrepare/ARM/branch-on-zero.ll (+23) 
- (added) llvm/test/Transforms/CodeGenPrepare/RISCV/convert-to-eqz.ll (+80) 


``diff
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp 
b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 8ee1f19e083e4e..1cca56fc19cfd8 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -8154,6 +8154,7 @@ static bool optimizeBranch(BranchInst *Branch, const 
TargetLowering &TLI,
   IRBuilder<> Builder(Branch);
   if (UI->getParent() != Branch->getParent())
 UI->moveBefore(Branch);
+  UI->dropPoisonGeneratingFlags();
   Value *NewCmp = Builder.CreateCmp(ICmpInst::ICMP_EQ, UI,
 ConstantInt::get(UI->getType(), 0));
   LLVM_DEBUG(dbgs() << "Converting " << *Cmp << "\n");
@@ -8167,6 +8168,7 @@ static bool optimizeBranch(BranchInst *Branch, const 
TargetLowering &TLI,
   IRBuilder<> Builder(Branch);
   if (UI->getParent() != Branch->getParent())
 UI->moveBefore(Branch);
+  UI->dropPoisonGeneratingFlags();
   Value *NewCmp = Builder.CreateCmp(Cmp->getPredicate(), UI,
 ConstantInt::get(UI->getType(), 0));
   LLVM_DEBUG(dbgs() << "Converting " << *Cmp << "\n");
diff --git a/llvm/test/Transforms/CodeGenPrepare/ARM/branch-on-zero.ll 
b/llvm/test/Transforms/CodeGenPrepare/ARM/branch-on-zero.ll
index ff5cef7e781fe6..25dfb3c53a077b 100644
--- a/llvm/test/Transforms/CodeGenPrepare/ARM/branch-on-zero.ll
+++ b/llvm/test/Transforms/CodeGenPrepare/ARM/branch-on-zero.ll
@@ -211,6 +211,29 @@ else:
   ret i32 %l
 }
 
+define i32 @sub10_else_drop_nuw(i32 %a) {
+; CHECK-LABEL: @sub10_else_drop_nuw(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[L:%.*]] = sub i32 [[A:%.*]], 10
+; CHECK-NEXT:[[TMP0:%.*]] = icmp eq i32 [[L]], 0
+; CHECK-NEXT:br i1 [[TMP0]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK:   then:
+; CHECK-NEXT:ret i32 0
+; CHECK:   else:
+; CHECK-NEXT:ret i32 [[L]]
+;
+entry:
+  %c = icmp eq i32 %a, 10
+  br i1 %c, label %then, label %else
+
+then:
+  ret i32 0
+
+else:
+  %l = sub nuw i32 %a, 10
+  ret i32 %l
+}
+
 define i32 @subm10_then(i32 %a) {
 ; CHECK-LABEL: @subm10_then(
 ; CHECK-NEXT:  entry:
diff --git a/llvm/test/Transforms/CodeGenPrepare/RISCV/convert-to-eqz.ll 
b/llvm/test/Transforms/CodeGenPrepare/RISCV/convert-to-eqz.ll
new file mode 100644
index 00..a6909d14913494
--- /dev/null
+++ b/llvm/test/Transforms/CodeGenPrepare/RISCV/convert-to-eqz.ll
@@ -0,0 +1,80 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 4
+; RUN: opt -codegenprepare -S -mtriple=riscv64 < %s | FileCheck %s
+
+define i8 @hoist_add(i8 %x) {
+; CHECK-LABEL: define i8 @hoist_add(
+; CHECK-SAME: i8 [[X:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[INC:%.*]] = add i8 [[X]], 1
+; CHECK-NEXT:[[TMP0:%.*]] = icmp eq i8 [[INC]], 0
+; CHECK-NEXT:br i1 [[TMP0]], label [[EXIT:%.*]], label [[IF_THEN:%.*]]
+; CHECK:   if.then:
+; CHECK-NEXT:br label [[EXIT]]
+; CHECK:   exit:
+; CHECK-NEXT:[[RETVAL:%.*]] = phi i8 [ [[INC]], [[IF_THEN]] ], [ -1, 
[[ENTRY:%.*]] ]
+; CHECK-NEXT:ret i8 [[RETVAL]]
+;
+entry:
+  %cmp = icmp eq i8 %x, -1
+  br i1 %cmp, label %exit, label %if.then
+
+if.then:
+  %inc = add nuw nsw i8 %x, 1
+  br label %exit
+
+exit:
+  %retval = phi i8 [ %inc, %if.then ], [ -1, %entry ]
+  ret i8 %retval
+}
+
+define i8 @hoist_lshr(i8 %x) {
+; CHECK-LABEL: define i8 @hoist_lshr(
+; CHECK-SAME: i8 [[X:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[INC:%.*]] = lshr i8 [[X]], 3
+; CHECK-NEXT:[[TMP0:%.*]] = icmp eq i8 [[INC]], 0
+; CHECK-NEXT:br i1 [[TMP0]], label [[EXIT:%.*]], label [[IF_THEN:%.*]]
+; CHECK:   if.then:
+; CHECK-NEXT:br label [[EXIT]]
+; CHECK:   exit:
+; CHECK-NEXT:[[RETVAL:%.*]] = phi i8 [ [[INC]], [[IF_THEN]] ], [ -1, 
[[ENTRY:%.*]] ]
+; CHECK-NEXT:ret i8 [[RETVAL]]
+;
+entry:
+  %cmp = icmp ult i8 %x, 8
+  br i1 %cmp, label %exit, label %if.then
+
+if.then:
+  %inc = lshr exact i8 %x, 3
+  br label %exit
+
+exit:
+  %retval = phi i8 [ %inc, %if.then ], [ -1, %entry ]
+  ret i8 %retval
+}
+
+define i8 @nomove_add(i8 %x) {
+; CHECK-LABEL: define i8 @nomove_add(
+; CHECK-SAME: i8 [[X:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[INC:%.*]] = add i8 [[X]], 1
+; CHECK-NEXT:[[TMP0:%.*]] = icmp eq i8 [[INC]], 0
+; CHECK-NEXT:br i1 [[TMP0]], label [[EXIT:%.*]], label [[IF_THEN:%.*]]
+; CHECK:   if.then:
+; CHECK-NEXT:br label [[EXIT]]
+; CHECK:   exit:
+; CHECK-NEXT:[[RETVAL:%.*]] = phi i8 [ [[INC]], [[IF_THEN]] ], [ 

[llvm-branch-commits] [llvm] release/18.x: [X86][EVEX512] Check hasEVEX512 for canExtendTo512DQ (#90390) (PR #90422)

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

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

LGTM

https://github.com/llvm/llvm-project/pull/90422
___
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: [CGP] Drop poison-generating flags after hoisting (#90382) (PR #90437)

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/90437
___
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 Lu Weining via llvm-branch-commits

https://github.com/SixWeining edited 
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 Lu Weining via llvm-branch-commits

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

LGTM except a nit.

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 Lu Weining 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()) {

SixWeining wrote:

Is it better to sort alphabetically?

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] acc59b6 - Revert "[flang] Improve debug info for functions. (#90083)"

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

Author: David Spickett
Date: 2024-04-29T11:01:28+01:00
New Revision: acc59b62bc10fe034faf876c9a23f92dd4146505

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

LOG: Revert "[flang] Improve debug info for functions. (#90083)"

This reverts commit f029da5cfce66e2d460d5f54b17582810a9111ad.

Added: 


Modified: 
flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
flang/lib/Optimizer/Transforms/CMakeLists.txt
flang/test/Transforms/debug-line-table-inc-file.fir

Removed: 
flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
flang/lib/Optimizer/Transforms/DebugTypeGenerator.h
flang/test/Transforms/debug-fn-info.f90



diff  --git a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp 
b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
index 5108469cb6c84a..18d98a11ef3c40 100644
--- a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
+++ b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
@@ -11,7 +11,6 @@
 /// This pass populates some debug information for the module and functions.
 
//===--===//
 
-#include "DebugTypeGenerator.h"
 #include "flang/Common/Version.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Builder/Todo.h"
@@ -107,27 +106,14 @@ void AddDebugInfoPass::runOnOperation() {
   filePath = 
llvm::sys::path::parent_path(funcLoc.getFilename().getValue());
 }
 
-mlir::StringAttr fullName =
-mlir::StringAttr::get(context, funcOp.getName());
-auto result = fir::NameUniquer::deconstruct(funcOp.getName());
 mlir::StringAttr funcName =
-mlir::StringAttr::get(context, result.second.name);
-
-llvm::SmallVector types;
-fir::DebugTypeGenerator typeGen(module);
-for (auto resTy : funcOp.getResultTypes()) {
-  auto tyAttr =
-  typeGen.convertType(resTy, fileAttr, cuAttr, funcOp.getLoc());
-  types.push_back(tyAttr);
-}
-for (auto inTy : funcOp.getArgumentTypes()) {
-  auto tyAttr = typeGen.convertType(fir::unwrapRefType(inTy), fileAttr,
-cuAttr, funcOp.getLoc());
-  types.push_back(tyAttr);
-}
-
+mlir::StringAttr::get(context, funcOp.getName());
+mlir::LLVM::DIBasicTypeAttr bT = mlir::LLVM::DIBasicTypeAttr::get(
+context, llvm::dwarf::DW_TAG_base_type, "void", /*sizeInBits=*/0,
+/*encoding=*/1);
+// FIXME: Provide proper type for subroutine
 mlir::LLVM::DISubroutineTypeAttr subTypeAttr =
-mlir::LLVM::DISubroutineTypeAttr::get(context, CC, types);
+mlir::LLVM::DISubroutineTypeAttr::get(context, CC, {bT, bT});
 mlir::LLVM::DIFileAttr funcFileAttr =
 mlir::LLVM::DIFileAttr::get(context, fileName, filePath);
 
@@ -144,13 +130,11 @@ void AddDebugInfoPass::runOnOperation() {
   subprogramFlags =
   subprogramFlags | mlir::LLVM::DISubprogramFlags::Definition;
 }
-unsigned line = 1;
-if (auto funcLoc = l.dyn_cast())
-  line = funcLoc.getLine();
-
+// FIXME: Provide proper line and scopeline.
 auto spAttr = mlir::LLVM::DISubprogramAttr::get(
-context, id, compilationUnit, fileAttr, funcName, fullName,
-funcFileAttr, line, line, subprogramFlags, subTypeAttr);
+context, id, compilationUnit, fileAttr, funcName, funcName,
+funcFileAttr, /*line=*/1, /*scopeline=*/1, subprogramFlags,
+subTypeAttr);
 funcOp->setLoc(builder.getFusedLoc({funcOp->getLoc()}, spAttr));
   });
 }

diff  --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt 
b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index 5a542f237f8f98..fc08d67540ceb0 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -22,7 +22,6 @@ add_flang_library(FIRTransforms
   OMPMarkDeclareTarget.cpp
   VScaleAttr.cpp
   FunctionAttr.cpp
-  DebugTypeGenerator.cpp
 
   DEPENDS
   FIRDialect

diff  --git a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp 
b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
deleted file mode 100644
index 0057e08f8a763b..00
--- a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-//===-- DebugTypeGenerator.cpp -- type conversion ---*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
-//
-//===--===//
-
-#define DEBUG_TYPE "flang-debug-type-gene

[llvm-branch-commits] [clang] [CIR] Add options to emit ClangIR and enable the ClangIR pipeline (PR #89030)

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

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


https://github.com/llvm/llvm-project/pull/89030
___
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: [clang][CoverageMapping] do not emit a gap region when either end doesn't have valid source locations (#89564) (PR #90369)

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

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


https://github.com/llvm/llvm-project/pull/90369
___
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][DWARF] Include end_sequence debug_line rows when looking up addr ranges (PR #89703)

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

https://github.com/avillega updated 
https://github.com/llvm/llvm-project/pull/89703


___
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][DWARF] Include end_sequence debug_line rows when looking up addr ranges (PR #89703)

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

https://github.com/avillega updated 
https://github.com/llvm/llvm-project/pull/89703


___
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] [Serialization] Code cleanups and polish 83233 (PR #83237)

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

alexfh wrote:

Apologies for the delay with the reproducer. @ilya-biryukov is on vacation, but 
maybe @sam-mccall can help with an isolated test case. Either way it seems to 
be challenging.

https://github.com/llvm/llvm-project/pull/83237
___
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][COFF][Aarch64] Add _InterlockedAdd64 intrinsic (#81849) (PR #89951)

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

https://github.com/dpaoliello updated 
https://github.com/llvm/llvm-project/pull/89951

>From d1a4febc0974cb76bce1692be9d62aaa9a5dcefb Mon Sep 17 00:00:00 2001
From: Pierrick Bouvier 
Date: Fri, 16 Feb 2024 15:20:08 +0400
Subject: [PATCH] [COFF][Aarch64] Add _InterlockedAdd64 intrinsic (#81849)

Found when compiling openssl master branch using clang-cl.

This commit introduces usage of InterlockedAdd64:

https://github.com/openssl/openssl/commit/d0e1a0ae701cfaca7f3dd3bf28a3f934a6408813


https://learn.microsoft.com/en-us/cpp/intrinsics/interlockedadd-intrinsic-functions
---
 clang/include/clang/Basic/BuiltinsAArch64.def   |  1 +
 clang/lib/CodeGen/CGBuiltin.cpp |  3 ++-
 clang/lib/Headers/intrin.h  |  1 +
 clang/test/CodeGen/arm64-microsoft-intrinsics.c | 14 ++
 clang/test/CodeGen/ms-intrinsics-other.c|  9 +
 clang/test/CodeGen/ms-intrinsics-underaligned.c |  6 ++
 6 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index 31ec84143f65c1..b5cbe90c8fd6a3 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -139,6 +139,7 @@ TARGET_HEADER_BUILTIN(_BitScanForward64, "UcUNi*ULLi", 
"nh", INTRIN_H, ALL_MS_LA
 TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcUNi*ULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(_InterlockedAdd,   "NiNiD*Ni","nh", 
INTRIN_H, ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_InterlockedAdd64, "LLiLLiD*LLi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_InterlockedAnd64, "LLiLLiD*LLi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_InterlockedDecrement64,   "LLiLLiD*","nh", 
INTRIN_H, ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_InterlockedExchange64,"LLiLLiD*LLi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES, "")
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a4f26a6f0eb19b..05a898a24b5890 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -12044,7 +12044,8 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned 
BuiltinID,
 "vgetq_lane");
   }
 
-  case clang::AArch64::BI_InterlockedAdd: {
+  case clang::AArch64::BI_InterlockedAdd:
+  case clang::AArch64::BI_InterlockedAdd64: {
 Address DestAddr = CheckAtomicAlignment(*this, E);
 Value *Val = EmitScalarExpr(E->getArg(1));
 AtomicRMWInst *RMWI =
diff --git a/clang/lib/Headers/intrin.h b/clang/lib/Headers/intrin.h
index 9ebaea9fee9421..a6395143db54c2 100644
--- a/clang/lib/Headers/intrin.h
+++ b/clang/lib/Headers/intrin.h
@@ -551,6 +551,7 @@ static __inline__ void __DEFAULT_FN_ATTRS __nop(void) {
 #if defined(__aarch64__)
 unsigned __int64 __getReg(int);
 long _InterlockedAdd(long volatile *Addend, long Value);
+__int64 _InterlockedAdd64(__int64 volatile *Addend, __int64 Value);
 __int64 _ReadStatusReg(int);
 void _WriteStatusReg(int, __int64);
 
diff --git a/clang/test/CodeGen/arm64-microsoft-intrinsics.c 
b/clang/test/CodeGen/arm64-microsoft-intrinsics.c
index 44b2ee28fe5681..a354ed948ca5f1 100644
--- a/clang/test/CodeGen/arm64-microsoft-intrinsics.c
+++ b/clang/test/CodeGen/arm64-microsoft-intrinsics.c
@@ -21,6 +21,20 @@ long test_InterlockedAdd_constant(long volatile *Addend) {
 // CHECK-MSVC: ret i32 %[[NEWVAL:[0-9]+]]
 // CHECK-LINUX: error: call to undeclared function '_InterlockedAdd'
 
+__int64 test_InterlockedAdd64(__int64 volatile *Addend, __int64 Value) {
+  return _InterlockedAdd64(Addend, Value);
+}
+
+__int64 test_InterlockedAdd64_constant(__int64 volatile *Addend) {
+  return _InterlockedAdd64(Addend, -1);
+}
+
+// CHECK-LABEL: define {{.*}} i64 @test_InterlockedAdd64(ptr %Addend, i64 
%Value) {{.*}} {
+// CHECK-MSVC: %[[OLDVAL:[0-9]+]] = atomicrmw add ptr %1, i64 %2 seq_cst, 
align 8
+// CHECK-MSVC: %[[NEWVAL:[0-9]+]] = add i64 %[[OLDVAL:[0-9]+]], %2
+// CHECK-MSVC: ret i64 %[[NEWVAL:[0-9]+]]
+// CHECK-LINUX: error: call to undeclared function '_InterlockedAdd64'
+
 void check__dmb(void) {
   __dmb(0);
 }
diff --git a/clang/test/CodeGen/ms-intrinsics-other.c 
b/clang/test/CodeGen/ms-intrinsics-other.c
index 76f54add749669..36c40dddcbb4f5 100644
--- a/clang/test/CodeGen/ms-intrinsics-other.c
+++ b/clang/test/CodeGen/ms-intrinsics-other.c
@@ -240,6 +240,15 @@ LONG test_InterlockedAdd(LONG volatile *Addend, LONG 
Value) {
 // CHECK-ARM-ARM64: %[[OLDVAL:[0-9]+]] = atomicrmw add ptr %Addend, i32 %Value 
seq_cst, align 4
 // CHECK-ARM-ARM64: %[[NEWVAL:[0-9]+]] = add i32 %[[OLDVAL:[0-9]+]], %Value
 // CHECK-ARM-ARM64: ret i32 %[[NEWVAL:[0-9]+]]
+
+__int64 test_InterlockedAdd64(__int64 volatile *Addend, __int64 Value) {
+  return _InterlockedAdd64(Addend, Value);
+}
+
+// CHECK-ARM-ARM64: define{{.*}}i64 @test_InterlockedAdd64(ptr{{[a-z_ 
]*}}%Addend, i64 noundef %Value) {{.*}} {
+// CHECK-ARM-ARM6

[llvm-branch-commits] [clang] [release/18.x][COFF][Aarch64] Add _InterlockedAdd64 intrinsic (#81849) (PR #89951)

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

dpaoliello wrote:

> I think BuiltinsAArch64.def is part of clang's ABI, so changing it violates 
> the backport rules.
> 
> Otherwise, I'd be inclined to accept; it's kind of late to request, but it's 
> low risk.

@tstellar can you please advise if this change is ok to backport?

https://github.com/llvm/llvm-project/pull/89951
___
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][NFC] Document cl::opt variable and fix typo (PR #90145)

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

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/90145


___
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][NFC] Document cl::opt variable and fix typo (PR #90145)

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

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/90145


___
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][IR] Extend BranchWeightMetadata to track provenance of weights (PR #86609)

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

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/86609


___
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][IR] Extend BranchWeightMetadata to track provenance of weights (PR #86609)

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

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/86609


___
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][misexpect] Update MisExpect to use provenance tracking metadata (PR #86610)

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

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/86610


___
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][misexpect] Update MisExpect to use provenance tracking metadata (PR #86610)

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

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/86610


___
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][ProfDataUtils] provide getNumBranchWeights API (PR #90146)

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

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/90146


___
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][ProfDataUtils] provide getNumBranchWeights API (PR #90146)

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

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/90146


___
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 via llvm-branch-commits

https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/87573

>From a8a5848885e12c771f12cfa33b4dbc6a0272e925 Mon Sep 17 00:00:00 2001
From: Prabhuk 
Date: Mon, 22 Apr 2024 11:34:04 -0700
Subject: [PATCH 1/3] Update clang/lib/CodeGen/CodeGenModule.cpp

Cleaner if checks.

Co-authored-by: Matt Arsenault 
---
 clang/lib/CodeGen/CodeGenModule.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index e19bbee996f582..ff1586d2fa8abe 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2711,7 +2711,7 @@ void 
CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD,
 void CodeGenModule::CreateFunctionTypeMetadataForIcall(const QualType &QT,
llvm::CallBase *CB) {
   // Only if needed for call graph section and only for indirect calls.
-  if (!(CodeGenOpts.CallGraphSection && CB && CB->isIndirectCall()))
+  if (!CodeGenOpts.CallGraphSection || !CB || !CB->isIndirectCall())
 return;
 
   auto *MD = CreateMetadataIdentifierGeneralized(QT);

>From 019b2ca5e1c263183ed114e0b967b4e77b4a17a8 Mon Sep 17 00:00:00 2001
From: Prabhuk 
Date: Mon, 22 Apr 2024 11:34:31 -0700
Subject: [PATCH 2/3] Update clang/lib/CodeGen/CodeGenModule.cpp

Update the comments as suggested.

Co-authored-by: Matt Arsenault 
---
 clang/lib/CodeGen/CodeGenModule.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index ff1586d2fa8abe..5635a87d2358a7 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2680,9 +2680,9 @@ void 
CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD,
   bool EmittedMDIdGeneralized = false;
   if (CodeGenOpts.CallGraphSection &&
   (!F->hasLocalLinkage() ||
-   F->getFunction().hasAddressTaken(nullptr, /* IgnoreCallbackUses */ true,
-/* IgnoreAssumeLikeCalls */ true,
-/* IgnoreLLVMUsed */ false))) {
+   F->getFunction().hasAddressTaken(nullptr, /*IgnoreCallbackUses=*/ true,
+/*IgnoreAssumeLikeCalls=*/ true,
+/*IgnoreLLVMUsed=*/ false))) {
 F->addTypeMetadata(0, CreateMetadataIdentifierGeneralized(FD->getType()));
 EmittedMDIdGeneralized = true;
   }

>From 99242900c51778abd4b7e7f4361b09202b7abcda Mon Sep 17 00:00:00 2001
From: Prabhuk 
Date: Mon, 29 Apr 2024 11:53:40 -0700
Subject: [PATCH 3/3] dyn_cast to isa

Created using spr 1.3.6-beta.1
---
 clang/lib/CodeGen/CGCall.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 526a63b24ff834..45033ced1d8344 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5713,8 +5713,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 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 (dyn_cast(FD) || dyn_cast(FD) ||
-dyn_cast(FD)) {
+if (isa(FD) || isa(FD) ||
+isa(FD)) {
   CGM.CreateFunctionTypeMetadataForIcall(FD->getType(), *callOrInvoke);
 }
   }

___
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] [CallSiteInfo][CallGraphSection] Extend CallSiteInfo with TypeId (PR #87574)

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

https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/87574


___
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] [CallSiteInfo][CallGraphSection] Extend CallSiteInfo with TypeId (PR #87574)

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

https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/87574


___
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] [CallSiteInfo][CallGraphSection] Extract and propagate indirect call type ids (PR #87575)

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

https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/87575


___
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] [CallSiteInfo][CallGraphSection] Extract and propagate indirect call type ids (PR #87575)

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

https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/87575


___
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] [AsmPrinter][CallGraphSection] Emit call graph section (PR #87576)

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

https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/87576


___
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] [AsmPrinter][CallGraphSection] Emit call graph section (PR #87576)

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

https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/87576


___
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 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 (dyn_cast(FD) || dyn_cast(FD) ||
+dyn_cast(FD)) {

Prabhuk wrote:

Thank you. Done.

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] [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/3] 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/3] 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/3] 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 Maksim Panchenko via llvm-branch-commits

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


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] [CallGraphSection] Add call graph section options and documentation (PR #87572)

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

ilovepi wrote:

A few comments.

1. I think its better to split the LLVM and clang changes into separate patches.
2. Please update the commit messages w/ the correct [clang] or [llvm] tag.
3. These should probably be some of the last patches to land. Enabling driver 
support in clang + documentation and release notes are normally the last step 
in landing a complex feature. The LLVM flag support is less important about 
where it is in the stack, since it's not exposed externally.

https://github.com/llvm/llvm-project/pull/87572
___
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] [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/2] 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/2] 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;
 

___
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

https://github.com/clementval created 
https://github.com/llvm/llvm-project/pull/90526

Lower locals allocation of cuda device, managed and unified variables to 
fir.cuda_alloc. Add fir.cuda_free in the function context finalization. 

>From 02d1ef45cae1ba973a51e5898f092403395c Mon Sep 17 00:00:00 2001
From: Valentin Clement 
Date: Mon, 29 Apr 2024 14:30:46 -0700
Subject: [PATCH] [flang][cuda] Lower device/managed/unified allocation to cuda
 ops

---
 .../flang/Optimizer/Builder/FIRBuilder.h  |  7 +
 flang/include/flang/Semantics/tools.h | 17 +++
 flang/lib/Lower/ConvertVariable.cpp   | 29 +++
 flang/lib/Optimizer/Builder/FIRBuilder.cpp| 25 +---
 flang/lib/Optimizer/Dialect/FIROps.cpp| 15 ++
 flang/test/Lower/CUDA/cuda-data-attribute.cuf | 25 
 6 files changed, 107 insertions(+), 11 deletions(-)

diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h 
b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
index e4c954159f71be..0d650f830b64e0 100644
--- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
@@ -708,6 +708,13 @@ mlir::Value createNullBoxProc(fir::FirOpBuilder &builder, 
mlir::Location loc,
 
 /// Set internal linkage attribute on a function.
 void setInternalLinkage(mlir::func::FuncOp);
+
+llvm::SmallVector
+elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape);
+
+llvm::SmallVector
+elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams);
+
 } // namespace fir::factory
 
 #endif // FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
diff --git a/flang/include/flang/Semantics/tools.h 
b/flang/include/flang/Semantics/tools.h
index da10969ebc7021..c9eb5bc857ac01 100644
--- a/flang/include/flang/Semantics/tools.h
+++ b/flang/include/flang/Semantics/tools.h
@@ -222,6 +222,23 @@ inline bool HasCUDAAttr(const Symbol &sym) {
   return false;
 }
 
+inline bool NeedCUDAAlloc(const Symbol &sym) {
+  bool inDeviceSubprogram{IsCUDADeviceContext(&sym.owner())};
+  if (const auto *details{
+  sym.GetUltimate().detailsIf()}) {
+if (details->cudaDataAttr() &&
+(*details->cudaDataAttr() == common::CUDADataAttr::Device ||
+*details->cudaDataAttr() == common::CUDADataAttr::Managed ||
+*details->cudaDataAttr() == common::CUDADataAttr::Unified)) {
+  // Descriptor is allocated on host when in host context.
+  if (Fortran::semantics::IsAllocatable(sym))
+return inDeviceSubprogram;
+  return true;
+}
+  }
+  return false;
+}
+
 const Scope *FindCUDADeviceContext(const Scope *);
 std::optional GetCUDADataAttr(const Symbol *);
 
diff --git a/flang/lib/Lower/ConvertVariable.cpp 
b/flang/lib/Lower/ConvertVariable.cpp
index 21db0cac11bf6a..9a17acf5b15c36 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -693,6 +693,22 @@ static mlir::Value 
createNewLocal(Fortran::lower::AbstractConverter &converter,
   if (ultimateSymbol.test(Fortran::semantics::Symbol::Flag::CrayPointee))
 return builder.create(loc, fir::ReferenceType::get(ty));
 
+  if (Fortran::semantics::NeedCUDAAlloc(ultimateSymbol)) {
+fir::CUDADataAttributeAttr cudaAttr =
+Fortran::lower::translateSymbolCUDADataAttribute(builder.getContext(),
+ ultimateSymbol);
+llvm::SmallVector indices;
+llvm::SmallVector elidedShape =
+fir::factory::elideExtentsAlreadyInType(ty, shape);
+llvm::SmallVector elidedLenParams =
+fir::factory::elideLengthsAlreadyInType(ty, lenParams);
+auto idxTy = builder.getIndexType();
+for (mlir::Value sh : elidedShape)
+  indices.push_back(builder.createConvert(loc, idxTy, sh));
+return builder.create(loc, ty, nm, symNm, cudaAttr,
+lenParams, indices);
+  }
+
   // Let the builder do all the heavy lifting.
   if (!Fortran::semantics::IsProcedurePointer(ultimateSymbol))
 return builder.allocateLocal(loc, ty, nm, symNm, shape, lenParams, isTarg);
@@ -927,6 +943,19 @@ static void 
instantiateLocal(Fortran::lower::AbstractConverter &converter,
   });
 }
   }
+  if (Fortran::semantics::NeedCUDAAlloc(var.getSymbol())) {
+auto *builder = &converter.getFirOpBuilder();
+mlir::Location loc = converter.getCurrentLocation();
+fir::ExtendedValue exv =
+converter.getSymbolExtendedValue(var.getSymbol(), &symMap);
+auto *sym = &var.getSymbol();
+converter.getFctCtx().attachCleanup([builder, loc, exv, sym]() {
+  fir::CUDADataAttributeAttr cudaAttr =
+  Fortran::lower::translateSymbolCUDADataAttribute(
+  builder->getContext(), *sym);
+  builder->create(loc, fir::getBase(exv), cudaAttr);
+});
+  }
 }
 
 //======//
diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp 
b/flang/lib/Op

[llvm-branch-commits] [flang] [flang][cuda] Lower device/managed/unified allocation to cuda ops (PR #90526)

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

llvmbot wrote:




@llvm/pr-subscribers-flang-fir-hlfir

Author: Valentin Clement (バレンタイン クレメン) (clementval)


Changes

Lower locals allocation of cuda device, managed and unified variables to 
fir.cuda_alloc. Add fir.cuda_free in the function context finalization. 

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


6 Files Affected:

- (modified) flang/include/flang/Optimizer/Builder/FIRBuilder.h (+7) 
- (modified) flang/include/flang/Semantics/tools.h (+17) 
- (modified) flang/lib/Lower/ConvertVariable.cpp (+29) 
- (modified) flang/lib/Optimizer/Builder/FIRBuilder.cpp (+14-11) 
- (modified) flang/lib/Optimizer/Dialect/FIROps.cpp (+15) 
- (modified) flang/test/Lower/CUDA/cuda-data-attribute.cuf (+25) 


``diff
diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h 
b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
index e4c954159f71be..0d650f830b64e0 100644
--- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
@@ -708,6 +708,13 @@ mlir::Value createNullBoxProc(fir::FirOpBuilder &builder, 
mlir::Location loc,
 
 /// Set internal linkage attribute on a function.
 void setInternalLinkage(mlir::func::FuncOp);
+
+llvm::SmallVector
+elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape);
+
+llvm::SmallVector
+elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams);
+
 } // namespace fir::factory
 
 #endif // FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
diff --git a/flang/include/flang/Semantics/tools.h 
b/flang/include/flang/Semantics/tools.h
index da10969ebc7021..c9eb5bc857ac01 100644
--- a/flang/include/flang/Semantics/tools.h
+++ b/flang/include/flang/Semantics/tools.h
@@ -222,6 +222,23 @@ inline bool HasCUDAAttr(const Symbol &sym) {
   return false;
 }
 
+inline bool NeedCUDAAlloc(const Symbol &sym) {
+  bool inDeviceSubprogram{IsCUDADeviceContext(&sym.owner())};
+  if (const auto *details{
+  sym.GetUltimate().detailsIf()}) {
+if (details->cudaDataAttr() &&
+(*details->cudaDataAttr() == common::CUDADataAttr::Device ||
+*details->cudaDataAttr() == common::CUDADataAttr::Managed ||
+*details->cudaDataAttr() == common::CUDADataAttr::Unified)) {
+  // Descriptor is allocated on host when in host context.
+  if (Fortran::semantics::IsAllocatable(sym))
+return inDeviceSubprogram;
+  return true;
+}
+  }
+  return false;
+}
+
 const Scope *FindCUDADeviceContext(const Scope *);
 std::optional GetCUDADataAttr(const Symbol *);
 
diff --git a/flang/lib/Lower/ConvertVariable.cpp 
b/flang/lib/Lower/ConvertVariable.cpp
index 21db0cac11bf6a..9a17acf5b15c36 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -693,6 +693,22 @@ static mlir::Value 
createNewLocal(Fortran::lower::AbstractConverter &converter,
   if (ultimateSymbol.test(Fortran::semantics::Symbol::Flag::CrayPointee))
 return builder.create(loc, fir::ReferenceType::get(ty));
 
+  if (Fortran::semantics::NeedCUDAAlloc(ultimateSymbol)) {
+fir::CUDADataAttributeAttr cudaAttr =
+Fortran::lower::translateSymbolCUDADataAttribute(builder.getContext(),
+ ultimateSymbol);
+llvm::SmallVector indices;
+llvm::SmallVector elidedShape =
+fir::factory::elideExtentsAlreadyInType(ty, shape);
+llvm::SmallVector elidedLenParams =
+fir::factory::elideLengthsAlreadyInType(ty, lenParams);
+auto idxTy = builder.getIndexType();
+for (mlir::Value sh : elidedShape)
+  indices.push_back(builder.createConvert(loc, idxTy, sh));
+return builder.create(loc, ty, nm, symNm, cudaAttr,
+lenParams, indices);
+  }
+
   // Let the builder do all the heavy lifting.
   if (!Fortran::semantics::IsProcedurePointer(ultimateSymbol))
 return builder.allocateLocal(loc, ty, nm, symNm, shape, lenParams, isTarg);
@@ -927,6 +943,19 @@ static void 
instantiateLocal(Fortran::lower::AbstractConverter &converter,
   });
 }
   }
+  if (Fortran::semantics::NeedCUDAAlloc(var.getSymbol())) {
+auto *builder = &converter.getFirOpBuilder();
+mlir::Location loc = converter.getCurrentLocation();
+fir::ExtendedValue exv =
+converter.getSymbolExtendedValue(var.getSymbol(), &symMap);
+auto *sym = &var.getSymbol();
+converter.getFctCtx().attachCleanup([builder, loc, exv, sym]() {
+  fir::CUDADataAttributeAttr cudaAttr =
+  Fortran::lower::translateSymbolCUDADataAttribute(
+  builder->getContext(), *sym);
+  builder->create(loc, fir::getBase(exv), cudaAttr);
+});
+  }
 }
 
 //======//
diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp 
b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
index a0fbae5b614cc7..a813b646087d73 100644
--- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp
+++ b/flang/lib/Optimizer/Builder/F

[llvm-branch-commits] [flang] [flang][cuda] Lower device/managed/unified allocation to cuda ops (PR #90526)

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

llvmbot wrote:




@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)


Changes

Lower locals allocation of cuda device, managed and unified variables to 
fir.cuda_alloc. Add fir.cuda_free in the function context finalization. 

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


6 Files Affected:

- (modified) flang/include/flang/Optimizer/Builder/FIRBuilder.h (+7) 
- (modified) flang/include/flang/Semantics/tools.h (+17) 
- (modified) flang/lib/Lower/ConvertVariable.cpp (+29) 
- (modified) flang/lib/Optimizer/Builder/FIRBuilder.cpp (+14-11) 
- (modified) flang/lib/Optimizer/Dialect/FIROps.cpp (+15) 
- (modified) flang/test/Lower/CUDA/cuda-data-attribute.cuf (+25) 


``diff
diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h 
b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
index e4c954159f71be..0d650f830b64e0 100644
--- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
@@ -708,6 +708,13 @@ mlir::Value createNullBoxProc(fir::FirOpBuilder &builder, 
mlir::Location loc,
 
 /// Set internal linkage attribute on a function.
 void setInternalLinkage(mlir::func::FuncOp);
+
+llvm::SmallVector
+elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape);
+
+llvm::SmallVector
+elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams);
+
 } // namespace fir::factory
 
 #endif // FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
diff --git a/flang/include/flang/Semantics/tools.h 
b/flang/include/flang/Semantics/tools.h
index da10969ebc7021..c9eb5bc857ac01 100644
--- a/flang/include/flang/Semantics/tools.h
+++ b/flang/include/flang/Semantics/tools.h
@@ -222,6 +222,23 @@ inline bool HasCUDAAttr(const Symbol &sym) {
   return false;
 }
 
+inline bool NeedCUDAAlloc(const Symbol &sym) {
+  bool inDeviceSubprogram{IsCUDADeviceContext(&sym.owner())};
+  if (const auto *details{
+  sym.GetUltimate().detailsIf()}) {
+if (details->cudaDataAttr() &&
+(*details->cudaDataAttr() == common::CUDADataAttr::Device ||
+*details->cudaDataAttr() == common::CUDADataAttr::Managed ||
+*details->cudaDataAttr() == common::CUDADataAttr::Unified)) {
+  // Descriptor is allocated on host when in host context.
+  if (Fortran::semantics::IsAllocatable(sym))
+return inDeviceSubprogram;
+  return true;
+}
+  }
+  return false;
+}
+
 const Scope *FindCUDADeviceContext(const Scope *);
 std::optional GetCUDADataAttr(const Symbol *);
 
diff --git a/flang/lib/Lower/ConvertVariable.cpp 
b/flang/lib/Lower/ConvertVariable.cpp
index 21db0cac11bf6a..9a17acf5b15c36 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -693,6 +693,22 @@ static mlir::Value 
createNewLocal(Fortran::lower::AbstractConverter &converter,
   if (ultimateSymbol.test(Fortran::semantics::Symbol::Flag::CrayPointee))
 return builder.create(loc, fir::ReferenceType::get(ty));
 
+  if (Fortran::semantics::NeedCUDAAlloc(ultimateSymbol)) {
+fir::CUDADataAttributeAttr cudaAttr =
+Fortran::lower::translateSymbolCUDADataAttribute(builder.getContext(),
+ ultimateSymbol);
+llvm::SmallVector indices;
+llvm::SmallVector elidedShape =
+fir::factory::elideExtentsAlreadyInType(ty, shape);
+llvm::SmallVector elidedLenParams =
+fir::factory::elideLengthsAlreadyInType(ty, lenParams);
+auto idxTy = builder.getIndexType();
+for (mlir::Value sh : elidedShape)
+  indices.push_back(builder.createConvert(loc, idxTy, sh));
+return builder.create(loc, ty, nm, symNm, cudaAttr,
+lenParams, indices);
+  }
+
   // Let the builder do all the heavy lifting.
   if (!Fortran::semantics::IsProcedurePointer(ultimateSymbol))
 return builder.allocateLocal(loc, ty, nm, symNm, shape, lenParams, isTarg);
@@ -927,6 +943,19 @@ static void 
instantiateLocal(Fortran::lower::AbstractConverter &converter,
   });
 }
   }
+  if (Fortran::semantics::NeedCUDAAlloc(var.getSymbol())) {
+auto *builder = &converter.getFirOpBuilder();
+mlir::Location loc = converter.getCurrentLocation();
+fir::ExtendedValue exv =
+converter.getSymbolExtendedValue(var.getSymbol(), &symMap);
+auto *sym = &var.getSymbol();
+converter.getFctCtx().attachCleanup([builder, loc, exv, sym]() {
+  fir::CUDADataAttributeAttr cudaAttr =
+  Fortran::lower::translateSymbolCUDADataAttribute(
+  builder->getContext(), *sym);
+  builder->create(loc, fir::getBase(exv), cudaAttr);
+});
+  }
 }
 
 //======//
diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp 
b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
index a0fbae5b614cc7..a813b646087d73 100644
--- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp
+++ b/flang/lib/Optimizer/Builder/F

[llvm-branch-commits] [libcxx] [flang] [lldb] [lld] [clang] [libc] [clang-tools-extra] [compiler-rt] [llvm] [msan] Unwind stack before fatal reports (PR #77168)

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

https://github.com/vitalybuka edited 
https://github.com/llvm/llvm-project/pull/77168
___
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] [compiler-rt] [test][hwasan] Test function name in summaries (PR #77391)

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

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

>From 23bf2a98a428fa6a866f64e2499793734b1a97a9 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Mon, 8 Jan 2024 15:27:19 -0800
Subject: [PATCH] undo some failing cases

Created using spr 1.3.4
---
 compiler-rt/test/hwasan/TestCases/halt-on-error.cpp   | 6 +++---
 compiler-rt/test/hwasan/TestCases/report-unmapped.cpp | 2 +-
 compiler-rt/test/hwasan/TestCases/use-after-free.c| 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/compiler-rt/test/hwasan/TestCases/halt-on-error.cpp 
b/compiler-rt/test/hwasan/TestCases/halt-on-error.cpp
index f587ee0fcabd30..7666baf9de79de 100644
--- a/compiler-rt/test/hwasan/TestCases/halt-on-error.cpp
+++ b/compiler-rt/test/hwasan/TestCases/halt-on-error.cpp
@@ -26,15 +26,15 @@ int main() {
   // COMMON: READ of size 4 at
   // When instrumenting with callbacks, main is actually #1, and #0 is 
__hwasan_load4.
   // COMMON: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-3]]
-  // COMMON: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in SigTrap
+  // COMMON: SUMMARY: HWAddressSanitizer: tag-mismatch
 
   // RECOVER: READ of size 1 at
   // RECOVER: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-7]]
-  // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in SigTrap
+  // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch
 
   // RECOVER: READ of size 1 at
   // RECOVER: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-11]]
-  // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in SigTrap
+  // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch
 
   // COMMON-NOT: tag-mismatch
 }
diff --git a/compiler-rt/test/hwasan/TestCases/report-unmapped.cpp 
b/compiler-rt/test/hwasan/TestCases/report-unmapped.cpp
index 1802e920f390a2..935cd71c8c9c96 100644
--- a/compiler-rt/test/hwasan/TestCases/report-unmapped.cpp
+++ b/compiler-rt/test/hwasan/TestCases/report-unmapped.cpp
@@ -36,4 +36,4 @@ int main(int argc, char **argv) {
 // CHECK: Tags for short granules around
 
 // Check that report is complete.
-// CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in SigTrap
+// CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch
diff --git a/compiler-rt/test/hwasan/TestCases/use-after-free.c 
b/compiler-rt/test/hwasan/TestCases/use-after-free.c
index e0afb767b05937..b3eed88600726c 100644
--- a/compiler-rt/test/hwasan/TestCases/use-after-free.c
+++ b/compiler-rt/test/hwasan/TestCases/use-after-free.c
@@ -38,6 +38,6 @@ int main() {
   // CHECK: #1 {{.*}} in main {{.*}}use-after-free.c:[[@LINE-24]]
   // CHECK: Memory tags around the buggy address (one tag corresponds to 16 
bytes):
   // CHECK: =>{{.*}}[[MEM_TAG]]
-  // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in SigTrap
+  // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch
   return r;
 }

___
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] [compiler-rt] [msan] Unwind stack before fatal reports (PR #77168)

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

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

>From a127373cf1ac1676ce17ce8dca909d0c3bce9d18 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Mon, 8 Jan 2024 11:45:37 -0800
Subject: [PATCH 1/2] [NFC][msan] Switch allocator interface to use
 BufferedStackTrace

We will need it to unwind for fatal errors.

Pull Request: https://github.com/llvm/llvm-project/pull/77363
---
 compiler-rt/lib/msan/msan.h | 23 ++--
 compiler-rt/lib/msan/msan_allocator.cpp | 29 +
 2 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/compiler-rt/lib/msan/msan.h b/compiler-rt/lib/msan/msan.h
index 25fa2212bdadd3..753e6b260734f9 100644
--- a/compiler-rt/lib/msan/msan.h
+++ b/compiler-rt/lib/msan/msan.h
@@ -255,18 +255,19 @@ char *GetProcSelfMaps();
 void InitializeInterceptors();
 
 void MsanAllocatorInit();
-void MsanDeallocate(StackTrace *stack, void *ptr);
-
-void *msan_malloc(uptr size, StackTrace *stack);
-void *msan_calloc(uptr nmemb, uptr size, StackTrace *stack);
-void *msan_realloc(void *ptr, uptr size, StackTrace *stack);
-void *msan_reallocarray(void *ptr, uptr nmemb, uptr size, StackTrace *stack);
-void *msan_valloc(uptr size, StackTrace *stack);
-void *msan_pvalloc(uptr size, StackTrace *stack);
-void *msan_aligned_alloc(uptr alignment, uptr size, StackTrace *stack);
-void *msan_memalign(uptr alignment, uptr size, StackTrace *stack);
+void MsanDeallocate(BufferedStackTrace *stack, void *ptr);
+
+void *msan_malloc(uptr size, BufferedStackTrace *stack);
+void *msan_calloc(uptr nmemb, uptr size, BufferedStackTrace *stack);
+void *msan_realloc(void *ptr, uptr size, BufferedStackTrace *stack);
+void *msan_reallocarray(void *ptr, uptr nmemb, uptr size,
+BufferedStackTrace *stack);
+void *msan_valloc(uptr size, BufferedStackTrace *stack);
+void *msan_pvalloc(uptr size, BufferedStackTrace *stack);
+void *msan_aligned_alloc(uptr alignment, uptr size, BufferedStackTrace *stack);
+void *msan_memalign(uptr alignment, uptr size, BufferedStackTrace *stack);
 int msan_posix_memalign(void **memptr, uptr alignment, uptr size,
-StackTrace *stack);
+BufferedStackTrace *stack);
 
 void InstallTrapHandler();
 void InstallAtExitHandler();
diff --git a/compiler-rt/lib/msan/msan_allocator.cpp 
b/compiler-rt/lib/msan/msan_allocator.cpp
index 72a7f980d39fb0..987c894c79d45e 100644
--- a/compiler-rt/lib/msan/msan_allocator.cpp
+++ b/compiler-rt/lib/msan/msan_allocator.cpp
@@ -178,7 +178,7 @@ void MsanThreadLocalMallocStorage::CommitBack() {
   allocator.DestroyCache(GetAllocatorCache(this));
 }
 
-static void *MsanAllocate(StackTrace *stack, uptr size, uptr alignment,
+static void *MsanAllocate(BufferedStackTrace *stack, uptr size, uptr alignment,
   bool zeroise) {
   if (size > max_malloc_size) {
 if (AllocatorMayReturnNull()) {
@@ -229,7 +229,7 @@ static void *MsanAllocate(StackTrace *stack, uptr size, 
uptr alignment,
   return allocated;
 }
 
-void MsanDeallocate(StackTrace *stack, void *p) {
+void MsanDeallocate(BufferedStackTrace *stack, void *p) {
   CHECK(p);
   UnpoisonParam(1);
   RunFreeHooks(p);
@@ -259,8 +259,8 @@ void MsanDeallocate(StackTrace *stack, void *p) {
   }
 }
 
-static void *MsanReallocate(StackTrace *stack, void *old_p, uptr new_size,
-uptr alignment) {
+static void *MsanReallocate(BufferedStackTrace *stack, void *old_p,
+uptr new_size, uptr alignment) {
   Metadata *meta = reinterpret_cast(allocator.GetMetaData(old_p));
   uptr old_size = meta->requested_size;
   uptr actually_allocated_size = allocator.GetActuallyAllocatedSize(old_p);
@@ -284,7 +284,7 @@ static void *MsanReallocate(StackTrace *stack, void *old_p, 
uptr new_size,
   return new_p;
 }
 
-static void *MsanCalloc(StackTrace *stack, uptr nmemb, uptr size) {
+static void *MsanCalloc(BufferedStackTrace *stack, uptr nmemb, uptr size) {
   if (UNLIKELY(CheckForCallocOverflow(size, nmemb))) {
 if (AllocatorMayReturnNull())
   return nullptr;
@@ -320,15 +320,15 @@ static uptr AllocationSizeFast(const void *p) {
   return reinterpret_cast(allocator.GetMetaData(p))->requested_size;
 }
 
-void *msan_malloc(uptr size, StackTrace *stack) {
+void *msan_malloc(uptr size, BufferedStackTrace *stack) {
   return SetErrnoOnNull(MsanAllocate(stack, size, sizeof(u64), false));
 }
 
-void *msan_calloc(uptr nmemb, uptr size, StackTrace *stack) {
+void *msan_calloc(uptr nmemb, uptr size, BufferedStackTrace *stack) {
   return SetErrnoOnNull(MsanCalloc(stack, nmemb, size));
 }
 
-void *msan_realloc(void *ptr, uptr size, StackTrace *stack) {
+void *msan_realloc(void *ptr, uptr size, BufferedStackTrace *stack) {
   if (!ptr)
 return SetErrnoOnNull(MsanAllocate(stack, size, sizeof(u64), false));
   if (size == 0) {
@@ -338,7 +338,8 @@ void *msan_realloc(void *ptr, uptr size, StackTrace *stack) 
{
   return SetErrno

[llvm-branch-commits] [compiler-rt] [test][hwasan] Test function name in summaries (PR #77391)

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

https://github.com/vitalybuka closed 
https://github.com/llvm/llvm-project/pull/77391
___
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 ready_for_review 
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 unused `llvm.experimental.hot()` (PR #84851)

2024-04-29 Thread Vitaly Buka 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."),

vitalybuka wrote:

I guess #84858

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 Kirill Stoimenov via llvm-branch-commits

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


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] [llvm] [IR] Introduce `llvm.experimental.hot()` (PR #84850)

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

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

>From 679055efe79a97c84c8ef675d7eb450c5df58a51 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Tue, 12 Mar 2024 12:01:01 -0700
Subject: [PATCH] Update llvm/docs/LangRef.rst

Co-authored-by: Nikita Popov 
---
 llvm/docs/LangRef.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 36f4c964ee296c..a707ab721a2b2a 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -27656,7 +27656,7 @@ This intrinsic returns true iff it's known that 
containing basic block is hot in
 profile.
 
 When used with profile based optimization allows to change program behaviour
-deppending on the code hotness.
+depending on the code hotness.
 
 Arguments:
 ""

___
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] [IR] Introduce `llvm.experimental.hot()` (PR #84850)

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


@@ -27639,6 +27639,54 @@ constant `true`. However it is always correct to 
replace
 it with any other `i1` value. Any pass can
 freely do it if it can benefit from non-default lowering.
 
+'``llvm.experimental.hot``' Intrinsic
+^
+
+Syntax:
+"""
+
+::
+
+  declare i1 @llvm.experimental.hot()
+
+Overview:
+"
+
+This intrinsic returns true iff it's known that containing basic block is hot 
in
+profile.
+
+When used with profile based optimization allows to change program behaviour
+deppending on the code hotness.
+
+Arguments:
+""
+
+None.
+
+Semantics:
+""
+
+The intrinsic ``@llvm.experimental.hot()`` returns either `true` or `false`,
+deppending on profile used. Expresion is evaluated as `true` iff profile and
+summary are availible and profile counter for the block reach hotness 
threshold.
+For each evaluation of a call to this intrinsic, the program must be valid and
+correct both if it returns `true` and if it returns `false`.
+
+When used in a branch condition, it allows us to choose between
+two alternative correct solutions for the same problem, like
+in example below:
+
+.. code-block:: text
+
+%cond = call i1 @llvm.experimental.hot()
+br i1 %cond, label %fast_path, label %slow_path
+
+  label %fast_path:

vitalybuka wrote:

copypasted mistake from @llvm.experimental.widenable.condition :)

https://github.com/llvm/llvm-project/pull/84850
___
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 Nikita Popov via llvm-branch-commits


@@ -2827,6 +2827,14 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst 
&CI) {
 }))
   return nullptr;
 break;
+  case Intrinsic::experimental_hot: {
+// The intrinsic declaration includes sideeffects to avoid it moved. This
+// prevents removing even if the intrinsic is unused. We should remove
+// unused ones to enabled other optimizations.
+if (CI.use_empty())
+  return eraseInstFromFunction(CI);

nikic wrote:

This should be handled inside wouldInstructionBeTriviallyDead.

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] [llvm] [IR] Introduce `llvm.experimental.hot()` (PR #84850)

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

https://github.com/vitalybuka edited 
https://github.com/llvm/llvm-project/pull/84850
___
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] [IR] Introduce `llvm.experimental.hot()` (PR #84850)

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

vitalybuka wrote:

> Please submit an RFC on discourse for this change.

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

https://github.com/llvm/llvm-project/pull/84850
___
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] [IR] Introduce `llvm.experimental.hot()` (PR #84850)

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


@@ -1722,6 +1722,11 @@ def int_debugtrap : Intrinsic<[]>,
 def int_ubsantrap : Intrinsic<[], [llvm_i8_ty],
   [IntrNoReturn, IntrCold, ImmArg>]>;
 
+// Return true if profile counter for containing block is hot.
+def int_experimental_hot : Intrinsic<[llvm_i1_ty], [],
+  [IntrInaccessibleMemOnly, IntrWriteMem,

vitalybuka wrote:

No, we have no more precise attribute. E.g. int_sideeffect is declared this way 
as well.
There are a few comments for similar cases around, I'll add one here to.
We need to lock intrinsic in place, without it, it will be moved to the entry 
block and value shared between users. So it will work as function level, vs 
block level.

With ThinLTO it should not be a problem, in postlink we rerun simplification 
and optimization with intrinsic lowered to  true or false. I tried to remove 
this attribute and make it function level, but can't measure perf difference.

Alternative is to have intrinsic without sideeffects but with dependency like 
this:
```
%condition = call i1 @llvm.experimenta.hot(i1 %ubsan_condition)
```
This way we can lock it in place. But this will not help us with assert() with 
sideeffects as we discussed before.

So I tried both with UBSAN, ThinLTO and plain, and 

```
call i1 @llvm.experimenta.hot()
```

is consistently, but close to noise, faster then:

```
call i1 @llvm.experimenta.hot(i1 %ubsan_condition)
```

I believe because  `or i1 %ubsan, @llvm.experimenta.hot()`  is more predictable 
for early transformation passes than `@llvm.experimenta.hot(i1 
%ubsan_condition)`.

Both intrinsic approaches faster then removing traps.

https://github.com/llvm/llvm-project/pull/84850
___
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] [IR] Introduce `llvm.experimental.hot()` (PR #84850)

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

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

>From 679055efe79a97c84c8ef675d7eb450c5df58a51 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Tue, 12 Mar 2024 12:01:01 -0700
Subject: [PATCH] Update llvm/docs/LangRef.rst

Co-authored-by: Nikita Popov 
---
 llvm/docs/LangRef.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 36f4c964ee296c..a707ab721a2b2a 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -27656,7 +27656,7 @@ This intrinsic returns true iff it's known that 
containing basic block is hot in
 profile.
 
 When used with profile based optimization allows to change program behaviour
-deppending on the code hotness.
+depending on the code hotness.
 
 Arguments:
 ""

___
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] [IR] Introduce `llvm.experimental.hot()` (PR #84850)

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

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

>From 679055efe79a97c84c8ef675d7eb450c5df58a51 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Tue, 12 Mar 2024 12:01:01 -0700
Subject: [PATCH] Update llvm/docs/LangRef.rst

Co-authored-by: Nikita Popov 
---
 llvm/docs/LangRef.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 36f4c964ee296c..a707ab721a2b2a 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -27656,7 +27656,7 @@ This intrinsic returns true iff it's known that 
containing basic block is hot in
 profile.
 
 When used with profile based optimization allows to change program behaviour
-deppending on the code hotness.
+depending on the code hotness.
 
 Arguments:
 ""

___
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] [llvm] a6319c3 - Revert "Make two texts static in `ReplayInlineAdvisor` (#79489)"

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

Author: Vitaly Buka
Date: 2024-02-21T16:05:56-08:00
New Revision: a6319c3d1c4a7083b5f148b3ca33cb2757ed469c

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

LOG: Revert "Make two texts static in `ReplayInlineAdvisor` (#79489)"

This reverts commit 67f9c35ffee1aea3fa8a18b57a7b27400a03435a.

Added: 


Modified: 
llvm/lib/Analysis/ReplayInlineAdvisor.cpp

Removed: 




diff  --git a/llvm/lib/Analysis/ReplayInlineAdvisor.cpp 
b/llvm/lib/Analysis/ReplayInlineAdvisor.cpp
index 0814483db343ce..2ca02eb1741712 100644
--- a/llvm/lib/Analysis/ReplayInlineAdvisor.cpp
+++ b/llvm/lib/Analysis/ReplayInlineAdvisor.cpp
@@ -43,8 +43,8 @@ ReplayInlineAdvisor::ReplayInlineAdvisor(
   //   main:3:1.1;
   // We use the callsite string after `at callsite` to replay inlining.
   line_iterator LineIt(*BufferOrErr.get(), /*SkipBlanks=*/true);
-  static const std::string PositiveRemark = "' inlined into '";
-  static const std::string NegativeRemark = "' will not be inlined into '";
+  const std::string PositiveRemark = "' inlined into '";
+  const std::string NegativeRemark = "' will not be inlined into '";
 
   for (; !LineIt.is_at_eof(); ++LineIt) {
 StringRef Line = *LineIt;



___
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 edited 
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


[llvm-branch-commits] [compiler-rt] [test][hwasan] Test function name in summaries (PR #77391)

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

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

>From 23bf2a98a428fa6a866f64e2499793734b1a97a9 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Mon, 8 Jan 2024 15:27:19 -0800
Subject: [PATCH 1/2] undo some failing cases

Created using spr 1.3.4
---
 compiler-rt/test/hwasan/TestCases/halt-on-error.cpp   | 6 +++---
 compiler-rt/test/hwasan/TestCases/report-unmapped.cpp | 2 +-
 compiler-rt/test/hwasan/TestCases/use-after-free.c| 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/compiler-rt/test/hwasan/TestCases/halt-on-error.cpp 
b/compiler-rt/test/hwasan/TestCases/halt-on-error.cpp
index f587ee0fcabd30..7666baf9de79de 100644
--- a/compiler-rt/test/hwasan/TestCases/halt-on-error.cpp
+++ b/compiler-rt/test/hwasan/TestCases/halt-on-error.cpp
@@ -26,15 +26,15 @@ int main() {
   // COMMON: READ of size 4 at
   // When instrumenting with callbacks, main is actually #1, and #0 is 
__hwasan_load4.
   // COMMON: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-3]]
-  // COMMON: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in SigTrap
+  // COMMON: SUMMARY: HWAddressSanitizer: tag-mismatch
 
   // RECOVER: READ of size 1 at
   // RECOVER: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-7]]
-  // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in SigTrap
+  // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch
 
   // RECOVER: READ of size 1 at
   // RECOVER: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-11]]
-  // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in SigTrap
+  // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch
 
   // COMMON-NOT: tag-mismatch
 }
diff --git a/compiler-rt/test/hwasan/TestCases/report-unmapped.cpp 
b/compiler-rt/test/hwasan/TestCases/report-unmapped.cpp
index 1802e920f390a2..935cd71c8c9c96 100644
--- a/compiler-rt/test/hwasan/TestCases/report-unmapped.cpp
+++ b/compiler-rt/test/hwasan/TestCases/report-unmapped.cpp
@@ -36,4 +36,4 @@ int main(int argc, char **argv) {
 // CHECK: Tags for short granules around
 
 // Check that report is complete.
-// CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in SigTrap
+// CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch
diff --git a/compiler-rt/test/hwasan/TestCases/use-after-free.c 
b/compiler-rt/test/hwasan/TestCases/use-after-free.c
index e0afb767b05937..b3eed88600726c 100644
--- a/compiler-rt/test/hwasan/TestCases/use-after-free.c
+++ b/compiler-rt/test/hwasan/TestCases/use-after-free.c
@@ -38,6 +38,6 @@ int main() {
   // CHECK: #1 {{.*}} in main {{.*}}use-after-free.c:[[@LINE-24]]
   // CHECK: Memory tags around the buggy address (one tag corresponds to 16 
bytes):
   // CHECK: =>{{.*}}[[MEM_TAG]]
-  // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in SigTrap
+  // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch
   return r;
 }

>From 3dc1e55b0a49a902cdb9abfdce3af9bb85489b70 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Mon, 8 Jan 2024 15:30:08 -0800
Subject: [PATCH 2/2] undo more

Created using spr 1.3.4
---
 compiler-rt/test/hwasan/TestCases/halt-on-error.cpp   | 6 +++---
 compiler-rt/test/hwasan/TestCases/report-unmapped.cpp | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/compiler-rt/test/hwasan/TestCases/halt-on-error.cpp 
b/compiler-rt/test/hwasan/TestCases/halt-on-error.cpp
index 7666baf9de79de..1a32e4bf4cc4b5 100644
--- a/compiler-rt/test/hwasan/TestCases/halt-on-error.cpp
+++ b/compiler-rt/test/hwasan/TestCases/halt-on-error.cpp
@@ -26,15 +26,15 @@ int main() {
   // COMMON: READ of size 4 at
   // When instrumenting with callbacks, main is actually #1, and #0 is 
__hwasan_load4.
   // COMMON: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-3]]
-  // COMMON: SUMMARY: HWAddressSanitizer: tag-mismatch
+  // COMMON: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in
 
   // RECOVER: READ of size 1 at
   // RECOVER: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-7]]
-  // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch
+  // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in
 
   // RECOVER: READ of size 1 at
   // RECOVER: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-11]]
-  // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch
+  // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in
 
   // COMMON-NOT: tag-mismatch
 }
diff --git a/compiler-rt/test/hwasan/TestCases/report-unmapped.cpp 
b/compiler-rt/test/hwasan/TestCases/report-unmapped.cpp
index 935cd71c8c9c96..a58e50a78d8750 100644
--- a/compiler-rt/test/hwasan/TestCases/report-unmapped.cpp
+++ b/compiler-rt/test/hwasan/TestCases/report-unmapped.cpp
@@ -36,4 +36,4 @@ int main(int argc, char **argv) {
 // CHECK: Tags for short granules around
 
 // Check that report is complete.
-// CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch
+// CHECK: SUMMARY: HWAddressSanitizer

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

[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] [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 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] [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] [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 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] [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

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 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] [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:

> 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


  1   2   >