[llvm] [RISCV] Implement RISCVTTIImpl::getPreferredAddressingMode for HasVendorXCVmem (PR #120533)
Philipp van Kempen via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 19 06:31:07 PST 2024
PhilippvK wrote:
> Can you add a test?
@wangpc-pp I looked for existing tests which perform a similar check but was not able to find anything useful. Hence I've tried to come up with a "minimal" example which shows that the heuristic is being applied.
I am not very happy with it and am happy about any feedback on how to make the test more compact / less flaky:
```ll
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -O3 -mtriple=riscv32 -mattr=+m,+xcvmem -verify-machineinstrs < %s \
; RUN: | FileCheck %s --check-prefixes=CHECK
define i32 @test_heuristic(ptr %a, ptr %b, i32 %c, i32 %d, i32 %e) nounwind {
; CHECK-LABEL: test_heuristic:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: beqz a0, .LBB0_4
; CHECK-NEXT: # %bb.1: # %prepare
; CHECK-NEXT: add a5, a1, a4
; CHECK-NEXT: add a3, a4, a3
; CHECK-NEXT: add a1, a1, a3
; CHECK-NEXT: .LBB0_2: # %loop
; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
; CHECK-NEXT: cv.lbu a3, (a5), 1
; CHECK-NEXT: cv.lbu a4, (a0), 1
; CHECK-NEXT: bne a5, a1, .LBB0_2
; CHECK-NEXT: # %bb.3:
; CHECK-NEXT: add a2, a4, a2
; CHECK-NEXT: mul a0, a2, a3
; CHECK-NEXT: .LBB0_4: # %exit
; CHECK-NEXT: ret
entry:
%4 = icmp eq ptr %a, null
br i1 %4, label %exit, label %prepare
prepare:
%20 = shl nsw i32 %e, 2
%21 = mul nuw nsw i32 %e, 3
%22 = shl nuw nsw i32 %e, 1
%23 = getelementptr inbounds i8, ptr %b, i32 %e
%24 = getelementptr inbounds i8, ptr %b, i32 %22
%25 = getelementptr inbounds i8, ptr %b, i32 %21
%26 = getelementptr inbounds i8, ptr %b, i32 %20
br label %loop
loop:
%28 = phi ptr [ %a, %prepare ], [ %68, %loop ]
%29 = phi ptr [ %b, %prepare ], [ %63, %loop ]
%30 = phi ptr [ %23, %prepare ], [ %64, %loop ]
%32 = phi i32 [ 0, %prepare ], [ %69, %loop ]
%37 = phi i32 [ 0, %prepare ], [ %54, %loop ]
%40 = load i8, ptr %29, align 1
%41 = zext i8 %40 to i32
%42 = load i8, ptr %30, align 1
%43 = zext i8 %42 to i32
%50 = load i8, ptr %28, align 1
%51 = zext i8 %50 to i32
%52 = add i32 %51, %c
%53 = mul i32 %52, %41
%54 = add i32 %53, %37
%55 = mul i32 %52, %43
%63 = getelementptr inbounds i8, ptr %29, i32 1
%64 = getelementptr inbounds i8, ptr %30, i32 1
%68 = getelementptr inbounds i8, ptr %28, i32 1
%69 = add nuw nsw i32 %32, 1
%70 = icmp eq i32 %69, %d
br i1 %70, label %exit, label %loop
exit:
%result = phi i32 [ 0, %entry ], [ %55, %loop ]
ret i32 %result
}
```
https://github.com/llvm/llvm-project/pull/120533
More information about the llvm-commits
mailing list