Skip to content

Commit c2072d9

Browse files
committed
[CVP] Support vectors for and elision
1 parent 3e7ddcc commit c2072d9

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "llvm/IR/Instructions.h"
3434
#include "llvm/IR/IntrinsicInst.h"
3535
#include "llvm/IR/Operator.h"
36+
#include "llvm/IR/PatternMatch.h"
3637
#include "llvm/IR/PassManager.h"
3738
#include "llvm/IR/Type.h"
3839
#include "llvm/IR/Value.h"
@@ -1189,21 +1190,20 @@ static bool processBinOp(BinaryOperator *BinOp, LazyValueInfo *LVI) {
11891190
}
11901191

11911192
static bool processAnd(BinaryOperator *BinOp, LazyValueInfo *LVI) {
1192-
if (BinOp->getType()->isVectorTy())
1193-
return false;
1193+
using namespace llvm::PatternMatch;
11941194

11951195
// Pattern match (and lhs, C) where C includes a superset of bits which might
11961196
// be set in lhs. This is a common truncation idiom created by instcombine.
11971197
const Use &LHS = BinOp->getOperandUse(0);
1198-
ConstantInt *RHS = dyn_cast<ConstantInt>(BinOp->getOperand(1));
1199-
if (!RHS || !RHS->getValue().isMask())
1198+
const APInt *RHS;
1199+
if (!match(BinOp->getOperand(1), m_LowBitMask(RHS)))
12001200
return false;
12011201

12021202
// We can only replace the AND with LHS based on range info if the range does
12031203
// not include undef.
12041204
ConstantRange LRange =
12051205
LVI->getConstantRangeAtUse(LHS, /*UndefAllowed=*/false);
1206-
if (!LRange.getUnsignedMax().ule(RHS->getValue()))
1206+
if (!LRange.getUnsignedMax().ule(*RHS))
12071207
return false;
12081208

12091209
BinOp->replaceAllUsesWith(LHS);

llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,24 @@ define <2 x float> @sitofp(<2 x i8> %a) {
199199
ret <2 x float> %res
200200
}
201201

202-
; TODO: Add support for this.
203202
define <2 x i16> @and(<2 x i8> %a) {
204203
; CHECK-LABEL: define <2 x i16> @and(
205204
; CHECK-SAME: <2 x i8> [[A:%.*]]) {
206205
; CHECK-NEXT: [[ZEXT:%.*]] = zext <2 x i8> [[A]] to <2 x i16>
207-
; CHECK-NEXT: [[RES:%.*]] = and <2 x i16> [[ZEXT]], <i16 255, i16 255>
208-
; CHECK-NEXT: ret <2 x i16> [[RES]]
206+
; CHECK-NEXT: ret <2 x i16> [[ZEXT]]
209207
;
210208
%zext = zext <2 x i8> %a to <2 x i16>
211209
%res = and <2 x i16> %zext, splat (i16 u0xff)
212210
ret <2 x i16> %res
213211
}
212+
213+
define <2 x i16> @and_with_poison(<2 x i8> %a) {
214+
; CHECK-LABEL: define <2 x i16> @and_with_poison(
215+
; CHECK-SAME: <2 x i8> [[A:%.*]]) {
216+
; CHECK-NEXT: [[ZEXT:%.*]] = zext <2 x i8> [[A]] to <2 x i16>
217+
; CHECK-NEXT: ret <2 x i16> [[ZEXT]]
218+
;
219+
%zext = zext <2 x i8> %a to <2 x i16>
220+
%res = and <2 x i16> %zext, <i16 u0xff, i16 poison>
221+
ret <2 x i16> %res
222+
}

0 commit comments

Comments
 (0)