From 1dedd881327dc7b5609e49533b7e1aae1ef15e81 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Thu, 15 Sep 2011 06:25:02 -0700 Subject: [PATCH] Improve implementaton of 'are both masks equal' check for AVX. Previously, we did a vector equal compare and then a movmsk, the result of which we checked to see if it was on for all lanes. Because masks are vectors of i32s, under AVX, the vector equal compare required two 4-wide SSE compares and some shuffling. Now, we do a movmsk of both masks first and then a scalar equality comparison of those two values, which seems to generate overall better code. --- ctx.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ctx.cpp b/ctx.cpp index c645e0ba..a407bf92 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -704,6 +704,7 @@ FunctionEmitContext::LaneMask(llvm::Value *v) { llvm::Value * FunctionEmitContext::MasksAllEqual(llvm::Value *v1, llvm::Value *v2) { +#if 0 // Compare the two masks to get a vector of i1s llvm::Value *cmp = CmpInst(llvm::Instruction::ICmp, llvm::CmpInst::ICMP_EQ, v1, v2, "v1==v2"); @@ -711,6 +712,12 @@ FunctionEmitContext::MasksAllEqual(llvm::Value *v1, llvm::Value *v2) { cmp = I1VecToBoolVec(cmp); // And see if it's all on return All(cmp); +#else + llvm::Value *mm1 = LaneMask(v1); + llvm::Value *mm2 = LaneMask(v2); + return CmpInst(llvm::Instruction::ICmp, llvm::CmpInst::ICMP_EQ, mm1, mm2, + "v1==v2"); +#endif }