diff options
author | Nikita Popov <npopov@redhat.com> | 2024-07-03 14:40:09 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2024-07-03 14:40:48 +0200 |
commit | c2072d993a443f08ab1bac8a3d5575e1a48663c7 (patch) | |
tree | 8bfe2952dee988f4e705a5a073d2f17cc8f761cb | |
parent | 3e7ddcc3dcbe9b1e82473c0591af8b5fa24cbe7f (diff) | |
download | llvm-c2072d993a443f08ab1bac8a3d5575e1a48663c7.zip llvm-c2072d993a443f08ab1bac8a3d5575e1a48663c7.tar.gz llvm-c2072d993a443f08ab1bac8a3d5575e1a48663c7.tar.bz2 |
[CVP] Support vectors for and elision
-rw-r--r-- | llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp | 10 | ||||
-rw-r--r-- | llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll | 15 |
2 files changed, 17 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index 34304c2..2bfae0e 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -33,6 +33,7 @@ #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Operator.h" +#include "llvm/IR/PatternMatch.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/Type.h" #include "llvm/IR/Value.h" @@ -1189,21 +1190,20 @@ static bool processBinOp(BinaryOperator *BinOp, LazyValueInfo *LVI) { } static bool processAnd(BinaryOperator *BinOp, LazyValueInfo *LVI) { - if (BinOp->getType()->isVectorTy()) - return false; + using namespace llvm::PatternMatch; // Pattern match (and lhs, C) where C includes a superset of bits which might // be set in lhs. This is a common truncation idiom created by instcombine. const Use &LHS = BinOp->getOperandUse(0); - ConstantInt *RHS = dyn_cast<ConstantInt>(BinOp->getOperand(1)); - if (!RHS || !RHS->getValue().isMask()) + const APInt *RHS; + if (!match(BinOp->getOperand(1), m_LowBitMask(RHS))) return false; // We can only replace the AND with LHS based on range info if the range does // not include undef. ConstantRange LRange = LVI->getConstantRangeAtUse(LHS, /*UndefAllowed=*/false); - if (!LRange.getUnsignedMax().ule(RHS->getValue())) + if (!LRange.getUnsignedMax().ule(*RHS)) return false; BinOp->replaceAllUsesWith(LHS); diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll b/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll index a06fa2c..0024b0a 100644 --- a/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll +++ b/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll @@ -199,15 +199,24 @@ define <2 x float> @sitofp(<2 x i8> %a) { ret <2 x float> %res } -; TODO: Add support for this. define <2 x i16> @and(<2 x i8> %a) { ; CHECK-LABEL: define <2 x i16> @and( ; CHECK-SAME: <2 x i8> [[A:%.*]]) { ; CHECK-NEXT: [[ZEXT:%.*]] = zext <2 x i8> [[A]] to <2 x i16> -; CHECK-NEXT: [[RES:%.*]] = and <2 x i16> [[ZEXT]], <i16 255, i16 255> -; CHECK-NEXT: ret <2 x i16> [[RES]] +; CHECK-NEXT: ret <2 x i16> [[ZEXT]] ; %zext = zext <2 x i8> %a to <2 x i16> %res = and <2 x i16> %zext, splat (i16 u0xff) ret <2 x i16> %res } + +define <2 x i16> @and_with_poison(<2 x i8> %a) { +; CHECK-LABEL: define <2 x i16> @and_with_poison( +; CHECK-SAME: <2 x i8> [[A:%.*]]) { +; CHECK-NEXT: [[ZEXT:%.*]] = zext <2 x i8> [[A]] to <2 x i16> +; CHECK-NEXT: ret <2 x i16> [[ZEXT]] +; + %zext = zext <2 x i8> %a to <2 x i16> + %res = and <2 x i16> %zext, <i16 u0xff, i16 poison> + ret <2 x i16> %res +} |