[llvm] r181249 - InstCombine: (X ^ signbit) + C -> X + (signbit ^ C)
David Majnemer
david.majnemer at gmail.com
Mon May 6 14:21:32 PDT 2013
Author: majnemer
Date: Mon May 6 16:21:31 2013
New Revision: 181249
URL: http://llvm.org/viewvc/llvm-project?rev=181249&view=rev
Log:
InstCombine: (X ^ signbit) + C -> X + (signbit ^ C)
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/trunk/test/Transforms/InstCombine/sub-xor.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp?rev=181249&r1=181248&r2=181249&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Mon May 6 16:21:31 2013
@@ -974,6 +974,11 @@ Instruction *InstCombiner::visitAdd(Bina
return BinaryOperator::CreateSub(ConstantExpr::getAdd(XorRHS, CI),
XorLHS);
}
+ // (X + signbit) + C could have gotten canonicalized to (X ^ signbit) + C,
+ // transform them into (X + (signbit ^ C))
+ if (XorRHS->getValue().isSignBit())
+ return BinaryOperator::CreateAdd(XorLHS,
+ ConstantExpr::getXor(XorRHS, CI));
}
}
Modified: llvm/trunk/test/Transforms/InstCombine/sub-xor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/sub-xor.ll?rev=181249&r1=181248&r2=181249&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/sub-xor.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/sub-xor.ll Mon May 6 16:21:31 2013
@@ -35,3 +35,13 @@ define i32 @test3(i32 %x) nounwind {
; CHECK-NEXT: sub i32 73, %and
; CHECK-NEXT: ret
}
+
+define i32 @test4(i32 %x) nounwind {
+ %sub = xor i32 %x, 2147483648
+ %add = add i32 %sub, 42
+ ret i32 %add
+
+; CHECK: @test4
+; CHECK-NEXT: add i32 %x, -2147483606
+; CHECK-NEXT: ret
+}
More information about the llvm-commits
mailing list