[llvm-branch-commits] [llvm] 4bc88a0 - Enable support for floating-point division reductions
Author: Yichao Yu Date: 2020-11-23T20:00:58-05:00 New Revision: 4bc88a0e9a2ee29959a9053e867ae6f051348554 URL: https://github.com/llvm/llvm-project/commit/4bc88a0e9a2ee29959a9053e867ae6f051348554 DIFF: https://github.com/llvm/llvm-project/commit/4bc88a0e9a2ee29959a9053e867ae6f051348554.diff LOG: Enable support for floating-point division reductions Similar to fsub, fdiv can also be vectorized using fmul. Also http://llvm.org/viewvc/llvm-project?view=revision&revision=215200 Differential Revision: https://reviews.llvm.org/D34078 Co-authored-by: Jameson Nash Added: Modified: llvm/lib/Analysis/IVDescriptors.cpp llvm/test/Transforms/LoopVectorize/float-reduction.ll Removed: diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp index 86cbcb015f0f..a5cc622279c4 100644 --- a/llvm/lib/Analysis/IVDescriptors.cpp +++ b/llvm/lib/Analysis/IVDescriptors.cpp @@ -578,6 +578,7 @@ RecurrenceDescriptor::isRecurrenceInstr(Instruction *I, RecurrenceKind Kind, return InstDesc(Kind == RK_IntegerOr, I); case Instruction::Xor: return InstDesc(Kind == RK_IntegerXor, I); + case Instruction::FDiv: case Instruction::FMul: return InstDesc(Kind == RK_FloatMult, I, UAI); case Instruction::FSub: diff --git a/llvm/test/Transforms/LoopVectorize/float-reduction.ll b/llvm/test/Transforms/LoopVectorize/float-reduction.ll index f3b95d0ead7d..dec854845800 100644 --- a/llvm/test/Transforms/LoopVectorize/float-reduction.ll +++ b/llvm/test/Transforms/LoopVectorize/float-reduction.ll @@ -44,3 +44,47 @@ for.body: ; preds = %for.body, %entry for.end: ; preds = %for.body ret float %sub } + +;CHECK-LABEL: @foodiv( +;CHECK: fdiv fast <4 x float> +;CHECK: ret +define float @foodiv(float* nocapture %A, i32* nocapture %n) nounwind uwtable readonly ssp { +entry: + br label %for.body + +for.body: ; preds = %for.body, %entry + %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] + %sum.04 = phi float [ 1.00e+00, %entry ], [ %sub, %for.body ] + %arrayidx = getelementptr inbounds float, float* %A, i64 %indvars.iv + %0 = load float, float* %arrayidx, align 4 + %sub = fdiv fast float %sum.04, %0 + %indvars.iv.next = add i64 %indvars.iv, 1 + %lftr.wideiv = trunc i64 %indvars.iv.next to i32 + %exitcond = icmp eq i32 %lftr.wideiv, 200 + br i1 %exitcond, label %for.end, label %for.body + +for.end: ; preds = %for.body + ret float %sub +} + +;CHECK-LABEL: @foonodiv( +;CHECK-NOT: fdiv fast <4 x float> +;CHECK: ret +define float @foonodiv(float* nocapture %A, i32* nocapture %n) nounwind uwtable readonly ssp { +entry: + br label %for.body + +for.body: ; preds = %for.body, %entry + %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] + %sum.04 = phi float [ 1.00e+00, %entry ], [ %sub, %for.body ] + %arrayidx = getelementptr inbounds float, float* %A, i64 %indvars.iv + %0 = load float, float* %arrayidx, align 4 + %sub = fdiv fast float %0, %sum.04 + %indvars.iv.next = add i64 %indvars.iv, 1 + %lftr.wideiv = trunc i64 %indvars.iv.next to i32 + %exitcond = icmp eq i32 %lftr.wideiv, 200 + br i1 %exitcond, label %for.end, label %for.body + +for.end: ; preds = %for.body + ret float %sub +} ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] 700cf7d - [VNCoercion] Disallow coercion between different ni addrspaces
Author: Valentin Churavy Date: 2020-12-07T20:19:48-05:00 New Revision: 700cf7dcc927c0ffddc0a1acbfde490f673ffb4a URL: https://github.com/llvm/llvm-project/commit/700cf7dcc927c0ffddc0a1acbfde490f673ffb4a DIFF: https://github.com/llvm/llvm-project/commit/700cf7dcc927c0ffddc0a1acbfde490f673ffb4a.diff LOG: [VNCoercion] Disallow coercion between different ni addrspaces I'm not sure if it would be legal by the IR reference to introduce an addrspacecast here, since the IR reference is a bit vague on the exact semantics, but at least for our usage of it (and I suspect for many other's usage) it is not. For us, addrspacecasts between non-integral address spaces carry frontend information that the optimizer cannot deduce afterwards in a generic way (though we have frontend specific passes in our pipline that do propagate these). In any case, I'm sure nobody is using it this way at the moment, since it would have introduced inttoptrs, which are definitely illegal. Fixes PR38375 Co-authored-by: Keno Fischer Reviewed By: reames Differential Revision: https://reviews.llvm.org/D50010 Added: Modified: llvm/lib/Transforms/Utils/VNCoercion.cpp llvm/test/Transforms/GVN/non-integral-pointers.ll Removed: diff --git a/llvm/lib/Transforms/Utils/VNCoercion.cpp b/llvm/lib/Transforms/Utils/VNCoercion.cpp index 3adb9d40b4ff..61cd8595a73b 100644 --- a/llvm/lib/Transforms/Utils/VNCoercion.cpp +++ b/llvm/lib/Transforms/Utils/VNCoercion.cpp @@ -37,23 +37,27 @@ bool canCoerceMustAliasedValueToLoad(Value *StoredVal, Type *LoadTy, if (StoreSize < DL.getTypeSizeInBits(LoadTy).getFixedSize()) return false; + bool StoredNI = DL.isNonIntegralPointerType(StoredTy->getScalarType()); + bool LoadNI = DL.isNonIntegralPointerType(LoadTy->getScalarType()); // Don't coerce non-integral pointers to integers or vice versa. - if (DL.isNonIntegralPointerType(StoredVal->getType()->getScalarType()) != - DL.isNonIntegralPointerType(LoadTy->getScalarType())) { + if (StoredNI != LoadNI) { // As a special case, allow coercion of memset used to initialize // an array w/null. Despite non-integral pointers not generally having a // specific bit pattern, we do assume null is zero. if (auto *CI = dyn_cast(StoredVal)) return CI->isNullValue(); return false; + } else if (StoredNI && LoadNI && + StoredTy->getPointerAddressSpace() != + LoadTy->getPointerAddressSpace()) { +return false; } // The implementation below uses inttoptr for vectors of unequal size; we // can't allow this for non integral pointers. We could teach it to extract // exact subvectors if desired. - if (DL.isNonIntegralPointerType(StoredTy->getScalarType()) && - StoreSize != DL.getTypeSizeInBits(LoadTy).getFixedSize()) + if (StoredNI && StoreSize != DL.getTypeSizeInBits(LoadTy).getFixedSize()) return false; return true; diff --git a/llvm/test/Transforms/GVN/non-integral-pointers.ll b/llvm/test/Transforms/GVN/non-integral-pointers.ll index 872b6648084e..56f9d3179c27 100644 --- a/llvm/test/Transforms/GVN/non-integral-pointers.ll +++ b/llvm/test/Transforms/GVN/non-integral-pointers.ll @@ -1,7 +1,7 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -gvn -S < %s | FileCheck %s -target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:4" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:4:5" target triple = "x86_64-unknown-linux-gnu" define void @f0(i1 %alwaysFalse, i64 %val, i64* %loc) { @@ -430,3 +430,20 @@ entry: declare void @use.v2(<2 x i64 addrspace(4)*>) declare void @use.v4(<4 x i64 addrspace(4)*>) + define i8 addrspace(5)* @multini(i1 %alwaysFalse, i8 addrspace(4)* %val, i8 addrspace(4)** %loc) { + ; CHECK-LABEL: @multini( + ; CHECK-NOT: inttoptr + ; CHECK-NOT: ptrtoint + ; CHECK-NOT: addrspacecast + entry: + store i8 addrspace(4)* %val, i8 addrspace(4)** %loc + br i1 %alwaysFalse, label %neverTaken, label %alwaysTaken + + neverTaken: + %loc.bc = bitcast i8 addrspace(4)** %loc to i8 addrspace(5)** + % diff erentas = load i8 addrspace(5)*, i8 addrspace(5)** %loc.bc + ret i8 addrspace(5)* % diff erentas + + alwaysTaken: + ret i8 addrspace(5)* null + } ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits