InstCombine: Allow folding of xor into icmp by changing the predicate for vectors
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 12 Feb 2015 20:26:46 +0000 (20:26 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 12 Feb 2015 20:26:46 +0000 (20:26 +0000)
The loop vectorizer can create this pattern.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228954 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
test/Transforms/InstCombine/not.ll

index c65441e1c85ee475f2fca3b6253f77305899e3db..6178d9c73a13d9e47e62cc360219b42fa109b44d 100644 (file)
@@ -2604,15 +2604,16 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
     }
   }
 
-
-  if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
-    if (RHS->isOne() && Op0->hasOneUse())
+  if (Constant *RHS = dyn_cast<Constant>(Op1)) {
+    if (RHS->isAllOnesValue() && Op0->hasOneUse())
       // xor (cmp A, B), true = not (cmp A, B) = !cmp A, B
       if (CmpInst *CI = dyn_cast<CmpInst>(Op0))
         return CmpInst::Create(CI->getOpcode(),
                                CI->getInversePredicate(),
                                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).
     if (CastInst *Op0C = dyn_cast<CastInst>(Op0)) {
       if (CmpInst *CI = dyn_cast<CmpInst>(Op0C->getOperand(0))) {
index 4012ce1ea4ba348c232a5511c71fa8c129626285..9d59edd7934da07eb114b6f54a762887b034e351 100644 (file)
@@ -52,3 +52,9 @@ entry:
        %retval67 = zext i1 %tmp3 to i8         ; <i8> [#uses=1]
        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
+}