diff options
author | Evan Cheng <evan.cheng@apple.com> | 2008-03-25 20:07:13 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2008-03-25 20:07:13 +0000 |
commit | e5cd803324dd81ea77ff22796f919cda8de5181d (patch) | |
tree | bae780720ba296a7baea44957888c442f8cb9628 | |
parent | 01b2df658cfa070e564d40186092a23fc2c6f273 (diff) | |
download | external_llvm-e5cd803324dd81ea77ff22796f919cda8de5181d.zip external_llvm-e5cd803324dd81ea77ff22796f919cda8de5181d.tar.gz external_llvm-e5cd803324dd81ea77ff22796f919cda8de5181d.tar.bz2 |
Handle a special case xor undef, undef -> 0. Technically this should be transformed to undef. But this is such a common idiom (misuse) we are going to handle it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48791 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 7 | ||||
-rw-r--r-- | test/Transforms/InstCombine/xor-undef.ll | 6 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 8ebd2cc..35715fb 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -4425,8 +4425,13 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { bool Changed = SimplifyCommutative(I); Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - if (isa<UndefValue>(Op1)) + if (isa<UndefValue>(Op1)) { + if (isa<UndefValue>(Op0)) + // Handle undef ^ undef -> 0 special case. This is a common + // idiom (misuse). + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); return ReplaceInstUsesWith(I, Op1); // X ^ undef -> undef + } // xor X, X = 0, even if X is nested in a sequence of Xor's. if (Instruction *Result = AssociativeOpt(I, XorSelf(Op1))) { diff --git a/test/Transforms/InstCombine/xor-undef.ll b/test/Transforms/InstCombine/xor-undef.ll new file mode 100644 index 0000000..c090223 --- /dev/null +++ b/test/Transforms/InstCombine/xor-undef.ll @@ -0,0 +1,6 @@ +; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep zeroinitializer + +define <2 x i64> @f() { + %tmp = xor <2 x i64> undef, undef + ret <2 x i64> %tmp +} |