[ConstFold] Don't fold calls with mismatching function type

With opaque pointers, this is no longer ensured through pointer
type identity.
This commit is contained in:
Nikita Popov 2022-03-11 14:08:06 +01:00
parent 38cadd90b7
commit 806450805d
2 changed files with 13 additions and 0 deletions

View File

@ -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.

View File

@ -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
}