From 4b06b1a0ee5955ba7a50e89115de67bb28a1ffad Mon Sep 17 00:00:00 2001 From: Hal Finkel Date: Sat, 23 Jun 2012 21:52:50 +0000 Subject: [PATCH] Allow BBVectorize to fuse compare instructions. llvm-svn: 159088 --- llvm/include/llvm/Transforms/Vectorize.h | 3 +++ llvm/lib/Transforms/Vectorize/BBVectorize.cpp | 8 ++++++ .../test/Transforms/BBVectorize/simple-sel.ll | 26 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/llvm/include/llvm/Transforms/Vectorize.h b/llvm/include/llvm/Transforms/Vectorize.h index 652916c26c22..d73db66377ca 100644 --- a/llvm/include/llvm/Transforms/Vectorize.h +++ b/llvm/include/llvm/Transforms/Vectorize.h @@ -49,6 +49,9 @@ struct VectorizeConfig { /// @brief Vectorize select instructions. bool VectorizeSelect; + /// @brief Vectorize comparison instructions. + bool VectorizeCmp; + /// @brief Vectorize getelementptr instructions. bool VectorizeGEP; diff --git a/llvm/lib/Transforms/Vectorize/BBVectorize.cpp b/llvm/lib/Transforms/Vectorize/BBVectorize.cpp index 8c442bf7a306..55e0da7ac0a9 100644 --- a/llvm/lib/Transforms/Vectorize/BBVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/BBVectorize.cpp @@ -104,6 +104,10 @@ static cl::opt NoSelect("bb-vectorize-no-select", cl::init(false), cl::Hidden, cl::desc("Don't try to vectorize select instructions")); +static cl::opt +NoCmp("bb-vectorize-no-cmp", cl::init(false), cl::Hidden, + cl::desc("Don't try to vectorize comparison instructions")); + static cl::opt NoGEP("bb-vectorize-no-gep", cl::init(false), cl::Hidden, cl::desc("Don't try to vectorize getelementptr instructions")); @@ -570,6 +574,9 @@ namespace { } else if (isa(I)) { if (!Config.VectorizeSelect) return false; + } else if (isa(I)) { + if (!Config.VectorizeCmp) + return false; } else if (GetElementPtrInst *G = dyn_cast(I)) { if (!Config.VectorizeGEP) return false; @@ -1990,6 +1997,7 @@ VectorizeConfig::VectorizeConfig() { VectorizeMath = !::NoMath; VectorizeFMA = !::NoFMA; VectorizeSelect = !::NoSelect; + VectorizeCmp = !::NoCmp; VectorizeGEP = !::NoGEP; VectorizeMemOps = !::NoMemOps; AlignedOnly = ::AlignedOnly; diff --git a/llvm/test/Transforms/BBVectorize/simple-sel.ll b/llvm/test/Transforms/BBVectorize/simple-sel.ll index 4daa5714fbd3..7fb9c8b74c0c 100644 --- a/llvm/test/Transforms/BBVectorize/simple-sel.ll +++ b/llvm/test/Transforms/BBVectorize/simple-sel.ll @@ -27,4 +27,30 @@ define double @test1(double %A1, double %A2, double %B1, double %B2, i1 %C1, i1 ; CHECK: ret double %R } +; Basic depth-3 chain with select (and vect. compare) +define double @test2(double %A1, double %A2, double %B1, double %B2) { +; CHECK: @test2 +; CHECK: %X1.v.i1.1 = insertelement <2 x double> undef, double %B1, i32 0 +; CHECK: %X1.v.i0.1 = insertelement <2 x double> undef, double %A1, i32 0 +; CHECK: %X1.v.i1.2 = insertelement <2 x double> %X1.v.i1.1, double %B2, i32 1 +; CHECK: %X1.v.i0.2 = insertelement <2 x double> %X1.v.i0.1, double %A2, i32 1 + %X1 = fsub double %A1, %B1 + %X2 = fsub double %A2, %B2 +; CHECK: %X1 = fsub <2 x double> %X1.v.i0.2, %X1.v.i1.2 + %Y1 = fmul double %X1, %A1 + %Y2 = fmul double %X2, %A2 +; CHECK: %Y1 = fmul <2 x double> %X1, %X1.v.i0.2 + %C1 = fcmp ogt double %X1, %A1 + %C2 = fcmp ogt double %X2, %A2 +; CHECK: %C1 = fcmp ogt <2 x double> %X1, %X1.v.i0.2 + %Z1 = select i1 %C1, double %Y1, double %B1 + %Z2 = select i1 %C2, double %Y2, double %B2 +; CHECK: %Z1 = select <2 x i1> %C1, <2 x double> %Y1, <2 x double> %X1.v.i1.2 + %R = fmul double %Z1, %Z2 +; CHECK: %Z1.v.r1 = extractelement <2 x double> %Z1, i32 0 +; CHECK: %Z1.v.r2 = extractelement <2 x double> %Z1, i32 1 +; CHECK: %R = fmul double %Z1.v.r1, %Z1.v.r2 + ret double %R +; CHECK: ret double %R +}