1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

InstCombine: Allow folding of xor into icmp by changing the predicate for vectors

The loop vectorizer can create this pattern.

llvm-svn: 228954
This commit is contained in:
Benjamin Kramer 2015-02-12 20:26:46 +00:00
parent e464edb2e9
commit 3b1b5b8725
2 changed files with 10 additions and 3 deletions

View File

@ -2604,15 +2604,16 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
} }
} }
if (Constant *RHS = dyn_cast<Constant>(Op1)) {
if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) { if (RHS->isAllOnesValue() && Op0->hasOneUse())
if (RHS->isOne() && Op0->hasOneUse())
// xor (cmp A, B), true = not (cmp A, B) = !cmp A, B // xor (cmp A, B), true = not (cmp A, B) = !cmp A, B
if (CmpInst *CI = dyn_cast<CmpInst>(Op0)) if (CmpInst *CI = dyn_cast<CmpInst>(Op0))
return CmpInst::Create(CI->getOpcode(), return CmpInst::Create(CI->getOpcode(),
CI->getInversePredicate(), CI->getInversePredicate(),
CI->getOperand(0), CI->getOperand(1)); CI->getOperand(0), CI->getOperand(1));
}
if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
// fold (xor(zext(cmp)), 1) and (xor(sext(cmp)), -1) to ext(!cmp). // fold (xor(zext(cmp)), 1) and (xor(sext(cmp)), -1) to ext(!cmp).
if (CastInst *Op0C = dyn_cast<CastInst>(Op0)) { if (CastInst *Op0C = dyn_cast<CastInst>(Op0)) {
if (CmpInst *CI = dyn_cast<CmpInst>(Op0C->getOperand(0))) { if (CmpInst *CI = dyn_cast<CmpInst>(Op0C->getOperand(0))) {

View File

@ -52,3 +52,9 @@ entry:
%retval67 = zext i1 %tmp3 to i8 ; <i8> [#uses=1] %retval67 = zext i1 %tmp3 to i8 ; <i8> [#uses=1]
ret i8 %retval67 ret i8 %retval67
} }
define <2 x i1> @test7(<2 x i32> %A, <2 x i32> %B) {
%cond = icmp sle <2 x i32> %A, %B
%Ret = xor <2 x i1> %cond, <i1 true, i1 true>
ret <2 x i1> %Ret
}