Jameson Nash 96ab74bf17
[InstCombine] remove undef loads, such as memcpy from undef (#143958)
Extend `isAllocSiteRemovable` to be able to check if the ModRef info
indicates the alloca is only Ref or only Mod, and be able to remove it
accordingly. It seemed that there were a surprising number of
benchmarks with this pattern which weren't getting optimized previously
(due to MemorySSA walk limits). There were somewhat more existing tests
than I'd like to have modified which were simply doing exactly this
pattern (and thus relying on undef memory). Claude code contributed the
new tests (and found an important typo that I'd made).

This implements the discussion in
https://github.com/llvm/llvm-project/pull/143782#discussion_r2142720376.
2025-06-20 10:32:31 -04:00

39 lines
1.6 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -passes=instcombine < %s | FileCheck %s
; Check that there's a call one call to @objc_msgSend_fpret with a
; float result
target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
%struct.NSObject = type { ptr }
%struct.NSArray = type { %struct.NSObject }
%struct.objc_class = type opaque
%struct.objc_selector = type opaque
@"\01L_OBJC_METH_VAR_NAME_112" = internal global [15 x i8] c"whiteComponent\00", section "__TEXT,__cstring,cstring_literals"
@"\01L_OBJC_SELECTOR_REFERENCES_81" = internal global ptr @"\01L_OBJC_METH_VAR_NAME_112", section "__OBJC,__message_refs,literal_pointers,no_dead_strip"
define void @bork(ptr %color, ptr %color.466) nounwind {
; CHECK-LABEL: @bork(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP103:%.*]] = load ptr, ptr [[COLOR:%.*]], align 4
; CHECK-NEXT: store ptr [[TMP103]], ptr [[COLOR_466:%.*]], align 4
; CHECK-NEXT: [[TMP105:%.*]] = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_81", align 4
; CHECK-NEXT: [[TMP107:%.*]] = call float @objc_msgSend_fpret(ptr [[TMP103]], ptr [[TMP105]]) #[[ATTR0:[0-9]+]]
; CHECK-NEXT: br label [[EXIT:%.*]]
; CHECK: exit:
; CHECK-NEXT: ret void
;
entry:
%tmp103 = load ptr, ptr %color, align 4
store ptr %tmp103, ptr %color.466, align 4
%tmp105 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_81", align 4
%tmp106 = load ptr, ptr %color.466, align 4
%tmp107 = call float @objc_msgSend_fpret( ptr %tmp106, ptr %tmp105 ) nounwind
br label %exit
exit:
ret void
}
declare void @objc_msgSend_fpret(ptr, ...)