llvm/llvm/test/Transforms/ArgumentPromotion/bitcasts.ll

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
; RUN: opt -S -passes=argpromotion < %s | FileCheck %s

; Test argument promotion involving bitcasts.

%opaque = type opaque

define internal i32 @callee_basic(ptr %p) {
; CHECK-LABEL: define {{[^@]+}}@callee_basic
; CHECK-SAME: (i32 [[P_0_VAL:%.*]], i32 [[P_4_VAL:%.*]]) {
; CHECK-NEXT:    [[Z:%.*]] = add i32 [[P_0_VAL]], [[P_4_VAL]]
; CHECK-NEXT:    ret i32 [[Z]]
;
  %x = load i32, ptr %p
  %p1 = getelementptr i8, ptr %p, i64 4
  %y = load i32, ptr %p1
  %z = add i32 %x, %y
  ret i32 %z
}

define void @caller_basic(ptr %p) {
; CHECK-LABEL: define {{[^@]+}}@caller_basic
; CHECK-SAME: (ptr [[P:%.*]]) {
; CHECK-NEXT:    [[P_VAL:%.*]] = load i32, ptr [[P]], align 4
; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr i8, ptr [[P]], i64 4
; CHECK-NEXT:    [[P_VAL1:%.*]] = load i32, ptr [[TMP2]], align 4
; CHECK-NEXT:    [[TMP4:%.*]] = call i32 @callee_basic(i32 [[P_VAL]], i32 [[P_VAL1]])
; CHECK-NEXT:    ret void
;
  call i32 @callee_basic(ptr %p)
  ret void
}

define internal i32 @callee_opaque(ptr %p) {
; CHECK-LABEL: define {{[^@]+}}@callee_opaque
; CHECK-SAME: (i32 [[P_0_VAL:%.*]], i32 [[P_4_VAL:%.*]]) {
; CHECK-NEXT:    [[Z:%.*]] = add i32 [[P_0_VAL]], [[P_4_VAL]]
; CHECK-NEXT:    ret i32 [[Z]]
;
  %x = load i32, ptr %p
  %p1.32 = getelementptr i32, ptr %p, i64 1
  %y = load i32, ptr %p1.32
  %z = add i32 %x, %y
  ret i32 %z
}

define void @caller_opaque(ptr %p) {
; CHECK-LABEL: define {{[^@]+}}@caller_opaque
; CHECK-SAME: (ptr [[P:%.*]]) {
; CHECK-NEXT:    [[P_VAL:%.*]] = load i32, ptr [[P]], align 4
; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr i8, ptr [[P]], i64 4
; CHECK-NEXT:    [[P_VAL1:%.*]] = load i32, ptr [[TMP3]], align 4
; CHECK-NEXT:    [[TMP5:%.*]] = call i32 @callee_opaque(i32 [[P_VAL]], i32 [[P_VAL1]])
; CHECK-NEXT:    ret void
;
  call i32 @callee_opaque(ptr %p)
  ret void
}