[llvm] 8064508 - [ConstFold] Don't fold calls with mismatching function type
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 11 05:09:32 PST 2022
Author: Nikita Popov
Date: 2022-03-11T14:09:23+01:00
New Revision: 806450805d3c2ca9948d37fcd5b5e334cfd74e5a
URL: https://github.com/llvm/llvm-project/commit/806450805d3c2ca9948d37fcd5b5e334cfd74e5a
DIFF: https://github.com/llvm/llvm-project/commit/806450805d3c2ca9948d37fcd5b5e334cfd74e5a.diff
LOG: [ConstFold] Don't fold calls with mismatching function type
With opaque pointers, this is no longer ensured through pointer
type identity.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/Transforms/InstCombine/opaque-ptr.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index fd82bacca7ec2..359d5bbf9ac14 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1388,6 +1388,8 @@ Constant *llvm::ConstantFoldCastOperand(unsigned Opcode, Constant *C,
bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
if (Call->isNoBuiltin())
return false;
+ if (Call->getFunctionType() != F->getFunctionType())
+ return false;
switch (F->getIntrinsicID()) {
// Operations that do not operate floating-point numbers and do not depend on
// FP environment can be folded even in strictfp functions.
diff --git a/llvm/test/Transforms/InstCombine/opaque-ptr.ll b/llvm/test/Transforms/InstCombine/opaque-ptr.ll
index 56ee71e13ea7c..dd347a9557b81 100644
--- a/llvm/test/Transforms/InstCombine/opaque-ptr.ll
+++ b/llvm/test/Transforms/InstCombine/opaque-ptr.ll
@@ -516,3 +516,14 @@ define void @call_cast_byval(ptr %p, ptr %p2) {
call void @call_byval(ptr %p, ptr byval(double) %p2)
ret void
}
+
+declare float @fmodf(float, float)
+
+define i32 @const_fold_call_with_func_type_mismatch() {
+; CHECK-LABEL: @const_fold_call_with_func_type_mismatch(
+; CHECK-NEXT: [[V:%.*]] = call float @fmodf(float 0x40091EB860000000, float 2.000000e+00)
+; CHECK-NEXT: ret i32 1066527622
+;
+ %v = call i32 @fmodf(float 0x40091EB860000000, float 2.000000e+00)
+ ret i32 %v
+}
More information about the llvm-commits
mailing list