llvm-project/llvm/test/Transforms/InstCombine/apint-call-cast-target.ll
Nikita Popov cc14ecc281
[InstCombine] Don't change fn signature for calls to declarations (#102596)
transformConstExprCastCall() implements a number of highly dubious
transforms attempting to make a call function type line up with the
function type of the called function. Historically, the main value this
had was to avoid function type mismatches due to pointer type
differences, which is no longer relevant with opaque pointers.

This patch is a step towards reducing the scope of the transform, by
applying it only to definitions, not declarations. For declarations, the
declared signature might not match the actual function signature, e.g.
`void @fn()` is sometimes used as a placeholder for functions with
unknown signature. The implementation already bailed out in some cases
for declarations, but I think it would be safer to disable the transform
entirely.

For the test cases, I've updated some of them to use definitions
instead, so that the test coverage is preserved.
2024-08-12 10:12:00 +02:00

44 lines
934 B
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
target datalayout = "e-p:32:32"
target triple = "i686-pc-linux-gnu"
define i32 @main2() {
; CHECK-LABEL: @main2(
; CHECK-NEXT: ret i32 0
;
ret i32 0
}
define ptr @ctime2(ptr %p) {
; CHECK-LABEL: @ctime2(
; CHECK-NEXT: ret ptr [[P:%.*]]
;
ret ptr %p
}
define ptr @ctime(ptr) {
; CHECK-LABEL: @ctime(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[I0:%.*]] = call i32 @main2()
; CHECK-NEXT: [[TMP1:%.*]] = inttoptr i32 [[I0]] to ptr
; CHECK-NEXT: ret ptr [[TMP1]]
;
entry:
%i0 = call ptr @main2( )
ret ptr %i0
}
define i32 @main() {
; CHECK-LABEL: @main(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[I1:%.*]] = call ptr @ctime2(ptr null)
; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint ptr [[I1]] to i32
; CHECK-NEXT: ret i32 [[TMP0]]
;
entry:
%i1 = call i32 @ctime2( ptr null )
ret i32 %i1
}