Gabriel Baraldi 5e0a06b34d
Move ExpandMemCmp and MergeIcmp to the middle end (#77370)
Moving these into the middle-end pipeline will allow for additional
optimization of the expansion result, such as CSE of redundant loads
(c.f. https://godbolt.org/z/bEna4Md9r). For now, we conservatively place
the passes at the end of the middle-end pipeline, so we mostly don't
benefit from additional optimizations yet. The pipeline position will be
moved in a future change.

This builds on work done by legrosbuffle in
https://reviews.llvm.org/D60318.

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 09:57:00 +02:00

35 lines
1.1 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: opt -passes=expand-memcmp -mtriple=loongarch64 -mattr=+d -S < %s | llc --mtriple=loongarch64 -mattr=+d | FileCheck %s
;; Before getSelectionDAGInfo() interface hooks were defined DAGBuilder
;; would crash.
define signext i32 @test1(ptr %buffer1, ptr %buffer2) {
; CHECK-LABEL: test1:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: ld.d $a2, $a0, 0
; CHECK-NEXT: ld.d $a3, $a1, 0
; CHECK-NEXT: revb.d $a2, $a2
; CHECK-NEXT: revb.d $a3, $a3
; CHECK-NEXT: bne $a2, $a3, .LBB0_3
; CHECK-NEXT: # %bb.1: # %loadbb1
; CHECK-NEXT: ld.d $a0, $a0, 8
; CHECK-NEXT: ld.d $a1, $a1, 8
; CHECK-NEXT: revb.d $a2, $a0
; CHECK-NEXT: revb.d $a3, $a1
; CHECK-NEXT: bne $a2, $a3, .LBB0_3
; CHECK-NEXT: # %bb.2:
; CHECK-NEXT: move $a0, $zero
; CHECK-NEXT: ret
; CHECK-NEXT: .LBB0_3: # %res_block
; CHECK-NEXT: sltu $a0, $a2, $a3
; CHECK-NEXT: sub.d $a0, $zero, $a0
; CHECK-NEXT: ori $a0, $a0, 1
; CHECK-NEXT: ret
entry:
%call = call signext i32 @memcmp(ptr %buffer1, ptr %buffer2, i64 16)
ret i32 %call
}
declare signext i32 @memcmp(ptr, ptr, i64)