Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CGP] Add generic TargetLowering::shouldAlignPointerArgs() implementa…
…tion This function was added for ARM targets, but aligning global/stack pointer arguments passed to memcpy/memmove/memset can improve code size and performance for all targets that don't have fast unaligned accesses. This adds a generic implementation that adjusts the alignment to pointer size if unaligned accesses are slow. Review D134168 suggests that this significantly improves performance on synthetic benchmarks such as Dhrystone on RV32 as it avoids memcpy() calls. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D134282
- Loading branch information
1 parent
f28c28e
commit bd87a24
Showing
10 changed files
with
138 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
llvm/test/Transforms/CodeGenPrepare/RISCV/adjust-memintrin-alignment.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
; RUN: opt -mtriple=riscv32 -data-layout="e-m:e-p:32:32" -S -codegenprepare < %s \ | ||
; RUN: | FileCheck %s '-D#NEW_ALIGNMENT=4' | ||
; RUN: opt -mtriple=riscv64 -data-layout="e-m:e-p:64:64" -S -codegenprepare < %s \ | ||
; RUN: | FileCheck %s '-D#NEW_ALIGNMENT=8' | ||
|
||
@str = private unnamed_addr constant [45 x i8] c"THIS IS A LONG STRING THAT SHOULD BE ALIGNED\00", align 1 | ||
|
||
|
||
declare void @use(ptr %arg) | ||
|
||
|
||
; CHECK: @[[STR:[a-zA-Z0-9_$"\\.-]+]] = private unnamed_addr constant [45 x i8] c"THIS IS A LONG STRING THAT SHOULD BE ALIGNED\00", align [[#NEW_ALIGNMENT]] | ||
|
||
define void @foo() { | ||
; CHECK-LABEL: @foo( | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[DST:%.*]] = alloca [45 x i8], align [[#NEW_ALIGNMENT]] | ||
; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i32(ptr align [[#NEW_ALIGNMENT]] [[DST]], ptr align [[#NEW_ALIGNMENT]] dereferenceable(31) @str, i32 31, i1 false) | ||
; CHECK-NEXT: ret void | ||
|
||
entry: | ||
%dst = alloca [45 x i8], align 1 | ||
tail call void @llvm.memcpy.p0i8.p0i8.i32(ptr align 1 %dst, ptr align 1 dereferenceable(31) @str, i32 31, i1 false) | ||
ret void | ||
} | ||
|
||
; negative test - check that we don't align objects that are too small | ||
define void @no_align(ptr %src) { | ||
; CHECK-LABEL: @no_align( | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[DST:%.*]] = alloca [3 x i8], align 1 | ||
; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i32(ptr align 1 [[DST]], ptr align 1 [[SRC:%.*]], i32 31, i1 false) | ||
; CHECK-NEXT: ret void | ||
; | ||
entry: | ||
%dst = alloca [3 x i8], align 1 | ||
tail call void @llvm.memcpy.p0i8.p0i8.i32(ptr align 1 %dst, ptr %src, i32 31, i1 false) | ||
ret void | ||
} | ||
|
||
; negative test - check that minsize requires at least 8 byte object size | ||
define void @no_align_minsize(ptr %src) minsize { | ||
; CHECK-LABEL: @no_align_minsize( | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[DST:%.*]] = alloca [7 x i8], align 1 | ||
; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i32(ptr align 1 [[DST]], ptr align 1 [[SRC:%.*]], i32 31, i1 false) | ||
; CHECK-NEXT: ret void | ||
; | ||
entry: | ||
%dst = alloca [7 x i8], align 1 | ||
tail call void @llvm.memcpy.p0i8.p0i8.i32(ptr align 1 %dst, ptr %src, i32 31, i1 false) | ||
ret void | ||
} | ||
|
||
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i1) |