[llvm] 52bffdf - [IPSCCP][FuncSpec] Protect against metadata access from call args. (#124284)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 25 02:59:54 PST 2025
Author: David Green
Date: 2025-01-25T10:59:50Z
New Revision: 52bffdf9f5bb72eb86249a012d08a40c90316dfb
URL: https://github.com/llvm/llvm-project/commit/52bffdf9f5bb72eb86249a012d08a40c90316dfb
DIFF: https://github.com/llvm/llvm-project/commit/52bffdf9f5bb72eb86249a012d08a40c90316dfb.diff
LOG: [IPSCCP][FuncSpec] Protect against metadata access from call args. (#124284)
Fixes an issue reported from #114964, where metadata arguments were
attempted to be accessed as constants.
Added:
llvm/test/Transforms/FunctionSpecialization/solver-constant-strictfpmetadata.ll
Modified:
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index 449d64d1614ff1..c13305ce5056d1 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -415,6 +415,8 @@ Constant *InstCostVisitor::visitCallBase(CallBase &I) {
for (unsigned Idx = 0, E = I.getNumOperands() - 1; Idx != E; ++Idx) {
Value *V = I.getOperand(Idx);
+ if (isa<MetadataAsValue>(V))
+ return nullptr;
Constant *C = findConstantFor(V);
if (!C)
return nullptr;
diff --git a/llvm/test/Transforms/FunctionSpecialization/solver-constant-strictfpmetadata.ll b/llvm/test/Transforms/FunctionSpecialization/solver-constant-strictfpmetadata.ll
new file mode 100644
index 00000000000000..99224b4efba6bc
--- /dev/null
+++ b/llvm/test/Transforms/FunctionSpecialization/solver-constant-strictfpmetadata.ll
@@ -0,0 +1,17 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -passes=ipsccp -force-specialization -S < %s | FileCheck %s
+
+define float @test(ptr %this, float %cm, i1 %0) strictfp {
+; CHECK-LABEL: define float @test(
+; CHECK-SAME: ptr [[THIS:%.*]], float [[CM:%.*]], i1 [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[CMP:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f32(float [[CM]], float 0.000000e+00, metadata !"ole", metadata !"fpexcept.strict")
+; CHECK-NEXT: [[CALL295:%.*]] = call float @test.specialized.1(ptr null, float 0.000000e+00, i1 false)
+; CHECK-NEXT: ret float 0.000000e+00
+;
+entry:
+ %cmp = call i1 @llvm.experimental.constrained.fcmps.f32(float %cm, float 0.000000e+00, metadata !"ole", metadata !"fpexcept.strict") #0
+ %call295 = call float @test(ptr null, float 0.000000e+00, i1 false) #0
+ ret float 0.000000e+00
+}
+
More information about the llvm-commits
mailing list