[clang] [llvm] [AssumptionCache] Deduplicate affected values in removeAffectedValues (PR #205441)
Krisitan Erik Olsen via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 24 17:07:15 PDT 2026
https://github.com/Kristianerik updated https://github.com/llvm/llvm-project/pull/205441
>From abeb44a456009d54c0847a70d3574e6a262af71c Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Thu, 25 Jun 2026 01:58:54 +0200
Subject: [PATCH] [AssumptionCache] Deduplicate affected values in
removeAffectedValues
---
clang/lib/Driver/Driver.cpp | 4 ++++
clang/test/Driver/sycl-print-internal-defines.cpp | 8 ++++++++
llvm/lib/Analysis/AssumptionCache.cpp | 8 +++++++-
.../duplicate-affected-value.ll | 12 ++++++++++++
4 files changed, 31 insertions(+), 1 deletion(-)
create mode 100644 clang/test/Driver/sycl-print-internal-defines.cpp
create mode 100644 llvm/test/Transforms/DropUnnecessaryAssumes/duplicate-affected-value.ll
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 40953c0013f62..eb87bd2eebad0 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3134,6 +3134,8 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
Diag(clang::diag::warn_drv_unused_x) << LastXArg->getValue();
}
+ bool IsSYCL = Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false);
+
for (Arg *A : Args) {
if (A->getOption().getKind() == Option::InputClass) {
const char *Value = A->getValue();
@@ -3151,6 +3153,8 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
Ty = types::TY_Fortran;
} else if (IsDXCMode()) {
Ty = types::TY_HLSL;
+ } else if (IsSYCL) {
+ Ty = types::TY_CXX;
} else {
// If running with -E, treat as a C input (this changes the
// builtin macros, for example). This may be overridden by -ObjC
diff --git a/clang/test/Driver/sycl-print-internal-defines.cpp b/clang/test/Driver/sycl-print-internal-defines.cpp
new file mode 100644
index 0000000000000..389aaf25608c6
--- /dev/null
+++ b/clang/test/Driver/sycl-print-internal-defines.cpp
@@ -0,0 +1,8 @@
+// Test that clang can print defines in SYCL mode.
+
+// RUN: %clangxx -fsycl -dM -E %s 2>&1 | FileCheck --check-prefix CHECK-PRINT-INTERNAL-DEFINES %s
+// CHECK-PRINT-INTERNAL-DEFINES: #define
+
+// Printing defines also works when input is stdin.
+// RUN: %clangxx -fsycl -dM -E - < /dev/null 2>&1 | FileCheck --check-prefixes=CHECK-PRINT-INTERNAL-DEFINES,CHECK-NO-ERROR %s
+// CHECK-NO-ERROR-NOT: error:
diff --git a/llvm/lib/Analysis/AssumptionCache.cpp b/llvm/lib/Analysis/AssumptionCache.cpp
index 94eb93e048720..8af6f42518ac6 100644
--- a/llvm/lib/Analysis/AssumptionCache.cpp
+++ b/llvm/lib/Analysis/AssumptionCache.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Analysis/AssumptionCache.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
@@ -130,14 +131,19 @@ void AssumptionCache::removeAffectedValues(AssumeInst *CI) {
// loop may then find only a match to a different AssumeInst, resulting in
// an assertion failure. Avoid this by counting the number of expected
// matches.
+ SmallDenseSet<std::pair<Value *, unsigned>, 16> Seen;
#ifndef NDEBUG
DenseMap<Value *, int> ExpectedMatches;
for (auto &AV : Affected)
- if (AffectedValues.find_as(AV.Assume) != AffectedValues.end())
+ if (Seen.insert({AV.Assume, AV.Index}).second &&
+ AffectedValues.find_as(AV.Assume) != AffectedValues.end())
ExpectedMatches[AV.Assume]++;
#endif
+ Seen.clear();
for (auto &AV : Affected) {
+ if (!Seen.insert({AV.Assume, AV.Index}).second)
+ continue;
auto AVI = AffectedValues.find_as(AV.Assume);
if (AVI == AffectedValues.end())
continue;
diff --git a/llvm/test/Transforms/DropUnnecessaryAssumes/duplicate-affected-value.ll b/llvm/test/Transforms/DropUnnecessaryAssumes/duplicate-affected-value.ll
new file mode 100644
index 0000000000000..415d0e3353350
--- /dev/null
+++ b/llvm/test/Transforms/DropUnnecessaryAssumes/duplicate-affected-value.ll
@@ -0,0 +1,12 @@
+; RUN: opt -passes=drop-unnecessary-assumes -S < %s | FileCheck %s
+; This test verifies that drop-unnecessary-assumes does not crash when
+; a separate_storage bundle has the same pointer for both arguments.
+
+; CHECK-LABEL: @f
+declare void @llvm.assume(i1)
+
+define void @f(ptr %p) {
+ call void @llvm.assume(i1 true) [ "separate_storage"(ptr %p, ptr %p), "dereferenceable"(ptr null, i64 0) ]
+ call void @llvm.assume(i1 true) [ "align"(ptr %p, i64 0) ]
+ ret void
+}
More information about the cfe-commits
mailing list