
Summary: This is a resurrection of work first proposed and discussed in Aug 2015: http://lists.llvm.org/pipermail/llvm-dev/2015-August/089384.html and initially landed (but then backed out) in Nov 2015: http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20151109/312083.html The @llvm.memcpy/memmove/memset intrinsics currently have an explicit argument which is required to be a constant integer. It represents the alignment of the dest (and source), and so must be the minimum of the actual alignment of the two. This change is the first in a series that allows source and dest to each have their own alignments by using the alignment attribute on their arguments. In this change we: 1) Remove the alignment argument. 2) Add alignment attributes to the source & dest arguments. We, temporarily, require that the alignments for source & dest be equal. For example, code which used to read: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 100, i32 4, i1 false) will now read call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %dest, i8* align 4 %src, i32 100, i1 false) Downstream users may have to update their lit tests that check for @llvm.memcpy/memmove/memset call/declaration patterns. The following extended sed script may help with updating the majority of your tests, but it does not catch all possible patterns so some manual checking and updating will be required. s~declare void @llvm\.mem(set|cpy|move)\.p([^(]*)\((.*), i32, i1\)~declare void @llvm.mem\1.p\2(\3, i1)~g s~call void @llvm\.memset\.p([^(]*)i8\(i8([^*]*)\* (.*), i8 (.*), i8 (.*), i32 [01], i1 ([^)]*)\)~call void @llvm.memset.p\1i8(i8\2* \3, i8 \4, i8 \5, i1 \6)~g s~call void @llvm\.memset\.p([^(]*)i16\(i8([^*]*)\* (.*), i8 (.*), i16 (.*), i32 [01], i1 ([^)]*)\)~call void @llvm.memset.p\1i16(i8\2* \3, i8 \4, i16 \5, i1 \6)~g s~call void @llvm\.memset\.p([^(]*)i32\(i8([^*]*)\* (.*), i8 (.*), i32 (.*), i32 [01], i1 ([^)]*)\)~call void @llvm.memset.p\1i32(i8\2* \3, i8 \4, i32 \5, i1 \6)~g s~call void @llvm\.memset\.p([^(]*)i64\(i8([^*]*)\* (.*), i8 (.*), i64 (.*), i32 [01], i1 ([^)]*)\)~call void @llvm.memset.p\1i64(i8\2* \3, i8 \4, i64 \5, i1 \6)~g s~call void @llvm\.memset\.p([^(]*)i128\(i8([^*]*)\* (.*), i8 (.*), i128 (.*), i32 [01], i1 ([^)]*)\)~call void @llvm.memset.p\1i128(i8\2* \3, i8 \4, i128 \5, i1 \6)~g s~call void @llvm\.memset\.p([^(]*)i8\(i8([^*]*)\* (.*), i8 (.*), i8 (.*), i32 ([0-9]*), i1 ([^)]*)\)~call void @llvm.memset.p\1i8(i8\2* align \6 \3, i8 \4, i8 \5, i1 \7)~g s~call void @llvm\.memset\.p([^(]*)i16\(i8([^*]*)\* (.*), i8 (.*), i16 (.*), i32 ([0-9]*), i1 ([^)]*)\)~call void @llvm.memset.p\1i16(i8\2* align \6 \3, i8 \4, i16 \5, i1 \7)~g s~call void @llvm\.memset\.p([^(]*)i32\(i8([^*]*)\* (.*), i8 (.*), i32 (.*), i32 ([0-9]*), i1 ([^)]*)\)~call void @llvm.memset.p\1i32(i8\2* align \6 \3, i8 \4, i32 \5, i1 \7)~g s~call void @llvm\.memset\.p([^(]*)i64\(i8([^*]*)\* (.*), i8 (.*), i64 (.*), i32 ([0-9]*), i1 ([^)]*)\)~call void @llvm.memset.p\1i64(i8\2* align \6 \3, i8 \4, i64 \5, i1 \7)~g s~call void @llvm\.memset\.p([^(]*)i128\(i8([^*]*)\* (.*), i8 (.*), i128 (.*), i32 ([0-9]*), i1 ([^)]*)\)~call void @llvm.memset.p\1i128(i8\2* align \6 \3, i8 \4, i128 \5, i1 \7)~g s~call void @llvm\.mem(cpy|move)\.p([^(]*)i8\(i8([^*]*)\* (.*), i8([^*]*)\* (.*), i8 (.*), i32 [01], i1 ([^)]*)\)~call void @llvm.mem\1.p\2i8(i8\3* \4, i8\5* \6, i8 \7, i1 \8)~g s~call void @llvm\.mem(cpy|move)\.p([^(]*)i16\(i8([^*]*)\* (.*), i8([^*]*)\* (.*), i16 (.*), i32 [01], i1 ([^)]*)\)~call void @llvm.mem\1.p\2i16(i8\3* \4, i8\5* \6, i16 \7, i1 \8)~g s~call void @llvm\.mem(cpy|move)\.p([^(]*)i32\(i8([^*]*)\* (.*), i8([^*]*)\* (.*), i32 (.*), i32 [01], i1 ([^)]*)\)~call void @llvm.mem\1.p\2i32(i8\3* \4, i8\5* \6, i32 \7, i1 \8)~g s~call void @llvm\.mem(cpy|move)\.p([^(]*)i64\(i8([^*]*)\* (.*), i8([^*]*)\* (.*), i64 (.*), i32 [01], i1 ([^)]*)\)~call void @llvm.mem\1.p\2i64(i8\3* \4, i8\5* \6, i64 \7, i1 \8)~g s~call void @llvm\.mem(cpy|move)\.p([^(]*)i128\(i8([^*]*)\* (.*), i8([^*]*)\* (.*), i128 (.*), i32 [01], i1 ([^)]*)\)~call void @llvm.mem\1.p\2i128(i8\3* \4, i8\5* \6, i128 \7, i1 \8)~g s~call void @llvm\.mem(cpy|move)\.p([^(]*)i8\(i8([^*]*)\* (.*), i8([^*]*)\* (.*), i8 (.*), i32 ([0-9]*), i1 ([^)]*)\)~call void @llvm.mem\1.p\2i8(i8\3* align \8 \4, i8\5* align \8 \6, i8 \7, i1 \9)~g s~call void @llvm\.mem(cpy|move)\.p([^(]*)i16\(i8([^*]*)\* (.*), i8([^*]*)\* (.*), i16 (.*), i32 ([0-9]*), i1 ([^)]*)\)~call void @llvm.mem\1.p\2i16(i8\3* align \8 \4, i8\5* align \8 \6, i16 \7, i1 \9)~g s~call void @llvm\.mem(cpy|move)\.p([^(]*)i32\(i8([^*]*)\* (.*), i8([^*]*)\* (.*), i32 (.*), i32 ([0-9]*), i1 ([^)]*)\)~call void @llvm.mem\1.p\2i32(i8\3* align \8 \4, i8\5* align \8 \6, i32 \7, i1 \9)~g s~call void @llvm\.mem(cpy|move)\.p([^(]*)i64\(i8([^*]*)\* (.*), i8([^*]*)\* (.*), i64 (.*), i32 ([0-9]*), i1 ([^)]*)\)~call void @llvm.mem\1.p\2i64(i8\3* align \8 \4, i8\5* align \8 \6, i64 \7, i1 \9)~g s~call void @llvm\.mem(cpy|move)\.p([^(]*)i128\(i8([^*]*)\* (.*), i8([^*]*)\* (.*), i128 (.*), i32 ([0-9]*), i1 ([^)]*)\)~call void @llvm.mem\1.p\2i128(i8\3* align \8 \4, i8\5* align \8 \6, i128 \7, i1 \9)~g The remaining changes in the series will: Step 2) Expand the IRBuilder API to allow creation of memcpy/memmove with differing source and dest alignments. Step 3) Update Clang to use the new IRBuilder API. Step 4) Update Polly to use the new IRBuilder API. Step 5) Update LLVM passes that create memcpy/memmove calls to use the new IRBuilder API, and those that use use MemIntrinsicInst::[get|set]Alignment() to use getDestAlignment() and getSourceAlignment() instead. Step 6) Remove the single-alignment IRBuilder API for memcpy/memmove, and the MemIntrinsicInst::[get|set]Alignment() methods. Reviewers: pete, hfinkel, lhames, reames, bollu Reviewed By: reames Subscribers: niosHD, reames, jholewinski, qcolombet, jfb, sanjoy, arsenm, dschuff, dylanmckay, mehdi_amini, sdardis, nemanjai, david2050, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, asb, rbar, johnrusso, simoncook, jordy.potman.lists, apazos, sabuasal, llvm-commits Differential Revision: https://reviews.llvm.org/D41675 llvm-svn: 322965
148 lines
5.7 KiB
LLVM
148 lines
5.7 KiB
LLVM
; RUN: llc < %s | FileCheck %s
|
|
;
|
|
; Generated with clang -O2 -S -emit-llvm
|
|
;
|
|
; /* Test 1 */
|
|
; extern "C" bool bar (long double);
|
|
; __attribute__((optnone))
|
|
; extern "C" bool foo(long double x, long double y)
|
|
; {
|
|
; return (x == y) || (bar(x));
|
|
; }
|
|
;
|
|
; /* Test 2 */
|
|
; struct FVector {
|
|
; float x, y, z;
|
|
; inline __attribute__((always_inline)) FVector(float f): x(f), y(f), z(f) {}
|
|
; inline __attribute__((always_inline)) FVector func(float p) const
|
|
; {
|
|
; if( x == 1.f ) {
|
|
; return *this;
|
|
; } else if( x < p ) {
|
|
; return FVector(0.f);
|
|
; }
|
|
; return FVector(x);
|
|
; }
|
|
; };
|
|
;
|
|
; __attribute__((optnone))
|
|
; int main()
|
|
; {
|
|
; FVector v(1.0);
|
|
; v = v.func(1.e-8);
|
|
; return 0;
|
|
; }
|
|
;
|
|
; ModuleID = 'test.cpp'
|
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
|
target triple = "x86_64-unknown-linux-gnu"
|
|
|
|
%struct.FVector = type { float, float, float }
|
|
|
|
define zeroext i1 @foo(x86_fp80 %x, x86_fp80 %y) noinline optnone {
|
|
entry:
|
|
%x.addr = alloca x86_fp80, align 16
|
|
%y.addr = alloca x86_fp80, align 16
|
|
store x86_fp80 %x, x86_fp80* %x.addr, align 16
|
|
store x86_fp80 %y, x86_fp80* %y.addr, align 16
|
|
%0 = load x86_fp80, x86_fp80* %x.addr, align 16
|
|
%1 = load x86_fp80, x86_fp80* %y.addr, align 16
|
|
%cmp = fcmp oeq x86_fp80 %0, %1
|
|
|
|
; Test 1
|
|
; Make sure that there is no dead code generated
|
|
; from Fast-ISel Phi-node handling. We should only
|
|
; see one movb of the constant 1, feeding the PHI
|
|
; node in lor.end. This covers the code path with
|
|
; handlePHINodesInSuccessorBlocks() returning true.
|
|
;
|
|
; CHECK-LABEL: foo:
|
|
; CHECK: movb $1,
|
|
; CHECK-NOT: movb $1,
|
|
; CHECK-LABEL: .LBB0_1:
|
|
|
|
br i1 %cmp, label %lor.end, label %lor.rhs
|
|
|
|
lor.rhs: ; preds = %entry
|
|
%2 = load x86_fp80, x86_fp80* %x.addr, align 16
|
|
%call = call zeroext i1 @bar(x86_fp80 %2)
|
|
br label %lor.end
|
|
|
|
lor.end: ; preds = %lor.rhs, %entry
|
|
%3 = phi i1 [ true, %entry ], [ %call, %lor.rhs ]
|
|
ret i1 %3
|
|
}
|
|
|
|
declare zeroext i1 @bar(x86_fp80)
|
|
|
|
define i32 @main() noinline optnone {
|
|
entry:
|
|
%retval = alloca i32, align 4
|
|
%v = alloca %struct.FVector, align 4
|
|
%ref.tmp = alloca %struct.FVector, align 4
|
|
%tmp = alloca { <2 x float>, float }, align 8
|
|
store i32 0, i32* %retval, align 4
|
|
%0 = bitcast %struct.FVector* %v to i8*
|
|
call void @llvm.lifetime.start.p0i8(i64 12, i8* %0) nounwind
|
|
%x.i = getelementptr inbounds %struct.FVector, %struct.FVector* %v, i64 0, i32 0
|
|
store float 1.000000e+00, float* %x.i, align 4
|
|
%y.i = getelementptr inbounds %struct.FVector, %struct.FVector* %v, i64 0, i32 1
|
|
store float 1.000000e+00, float* %y.i, align 4
|
|
%z.i = getelementptr inbounds %struct.FVector, %struct.FVector* %v, i64 0, i32 2
|
|
store float 1.000000e+00, float* %z.i, align 4
|
|
%x.i.1 = getelementptr inbounds %struct.FVector, %struct.FVector* %v, i64 0, i32 0
|
|
%1 = load float, float* %x.i.1, align 4
|
|
%cmp.i = fcmp oeq float %1, 1.000000e+00
|
|
br i1 %cmp.i, label %if.then.i, label %if.else.i
|
|
|
|
if.then.i: ; preds = %entry
|
|
%retval.sroa.0.0..sroa_cast.i = bitcast %struct.FVector* %v to <2 x float>*
|
|
%retval.sroa.0.0.copyload.i = load <2 x float>, <2 x float>* %retval.sroa.0.0..sroa_cast.i, align 4
|
|
%retval.sroa.6.0..sroa_idx16.i = getelementptr inbounds %struct.FVector, %struct.FVector* %v, i64 0, i32 2
|
|
%retval.sroa.6.0.copyload.i = load float, float* %retval.sroa.6.0..sroa_idx16.i, align 4
|
|
br label %func.exit
|
|
|
|
if.else.i: ; preds = %entry
|
|
|
|
; Test 2
|
|
; In order to feed the first PHI node in func.exit handlePHINodesInSuccessorBlocks()
|
|
; generates a local value instruction, but it cannot handle the second PHI node and
|
|
; returns false to let SelectionDAGISel handle both cases. Make sure the generated
|
|
; local value instruction is removed.
|
|
; CHECK-LABEL: main:
|
|
; CHECK-LABEL: .LBB1_2:
|
|
; CHECK: xorps [[REG:%xmm[0-7]]], [[REG]]
|
|
; CHECK-NOT: xorps [[REG]], [[REG]]
|
|
; CHECK-LABEL: .LBB1_3:
|
|
|
|
%cmp3.i = fcmp olt float %1, 0x3E45798EE0000000
|
|
br i1 %cmp3.i, label %func.exit, label %if.end.5.i
|
|
|
|
if.end.5.i: ; preds = %if.else.i
|
|
%retval.sroa.0.0.vec.insert13.i = insertelement <2 x float> undef, float %1, i32 0
|
|
%retval.sroa.0.4.vec.insert15.i = insertelement <2 x float> %retval.sroa.0.0.vec.insert13.i, float %1, i32 1
|
|
br label %func.exit
|
|
|
|
func.exit: ; preds = %if.then.i, %if.else.i, %if.end.5.i
|
|
%retval.sroa.6.0.i = phi float [ %retval.sroa.6.0.copyload.i, %if.then.i ], [ %1, %if.end.5.i ], [ 0.000000e+00, %if.else.i ]
|
|
%retval.sroa.0.0.i = phi <2 x float> [ %retval.sroa.0.0.copyload.i, %if.then.i ], [ %retval.sroa.0.4.vec.insert15.i, %if.end.5.i ], [ zeroinitializer, %if.else.i ]
|
|
%.fca.0.insert.i = insertvalue { <2 x float>, float } undef, <2 x float> %retval.sroa.0.0.i, 0
|
|
%.fca.1.insert.i = insertvalue { <2 x float>, float } %.fca.0.insert.i, float %retval.sroa.6.0.i, 1
|
|
store { <2 x float>, float } %.fca.1.insert.i, { <2 x float>, float }* %tmp, align 8
|
|
%2 = bitcast { <2 x float>, float }* %tmp to i8*
|
|
%3 = bitcast %struct.FVector* %ref.tmp to i8*
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %3, i8* align 4 %2, i64 12, i1 false)
|
|
%4 = bitcast %struct.FVector* %v to i8*
|
|
%5 = bitcast %struct.FVector* %ref.tmp to i8*
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %4, i8* align 4 %5, i64 12, i1 false)
|
|
%6 = bitcast %struct.FVector* %v to i8*
|
|
call void @llvm.lifetime.end.p0i8(i64 12, i8* %6) nounwind
|
|
ret i32 0
|
|
}
|
|
|
|
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) argmemonly nounwind
|
|
|
|
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i1) argmemonly nounwind
|
|
|
|
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) argmemonly nounwind
|