[llvm-commits] [llvm] r48792 - in /llvm/trunk: lib/CodeGen/SelectionDAG/DAGCombiner.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp lib/VMCore/ConstantFold.cpp test/CodeGen/X86/xor-undef.ll
Evan Cheng
evan.cheng at apple.com
Tue Mar 25 13:08:07 PDT 2008
Author: evancheng
Date: Tue Mar 25 15:08:07 2008
New Revision: 48792
URL: http://llvm.org/viewvc/llvm-project?rev=48792&view=rev
Log:
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.
Added:
llvm/trunk/test/CodeGen/X86/xor-undef.ll
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/trunk/lib/VMCore/ConstantFold.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=48792&r1=48791&r2=48792&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Tue Mar 25 15:08:07 2008
@@ -2119,6 +2119,9 @@
if (FoldedVOp.Val) return FoldedVOp;
}
+ // fold (xor undef, undef) -> 0. This is a common idiom (misuse).
+ if (N0.getOpcode() == ISD::UNDEF && N1.getOpcode() == ISD::UNDEF)
+ return DAG.getConstant(0, VT);
// fold (xor x, undef) -> undef
if (N0.getOpcode() == ISD::UNDEF)
return N0;
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=48792&r1=48791&r2=48792&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Tue Mar 25 15:08:07 2008
@@ -2245,6 +2245,12 @@
// Fold a bunch of operators when the RHS is undef.
if (N2.getOpcode() == ISD::UNDEF) {
switch (Opcode) {
+ case ISD::XOR:
+ if (N1.getOpcode() == ISD::UNDEF)
+ // Handle undef ^ undef -> 0 special case. This is a common
+ // idiom (misuse).
+ return getConstant(0, VT);
+ // fallthrough
case ISD::ADD:
case ISD::ADDC:
case ISD::ADDE:
@@ -2258,7 +2264,6 @@
case ISD::SDIV:
case ISD::UREM:
case ISD::SREM:
- case ISD::XOR:
return N2; // fold op(arg1, undef) -> undef
case ISD::MUL:
case ISD::AND:
Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=48792&r1=48791&r2=48792&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Tue Mar 25 15:08:07 2008
@@ -474,9 +474,14 @@
// Handle UndefValue up front
if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
switch (Opcode) {
+ case Instruction::Xor:
+ if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
+ // Handle undef ^ undef -> 0 special case. This is a common
+ // idiom (misuse).
+ return Constant::getNullValue(C1->getType());
+ // Fallthrough
case Instruction::Add:
case Instruction::Sub:
- case Instruction::Xor:
return UndefValue::get(C1->getType());
case Instruction::Mul:
case Instruction::And:
Added: llvm/trunk/test/CodeGen/X86/xor-undef.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/xor-undef.ll?rev=48792&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/xor-undef.ll (added)
+++ llvm/trunk/test/CodeGen/X86/xor-undef.ll Tue Mar 25 15:08:07 2008
@@ -0,0 +1,11 @@
+; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 | grep xor | count 2
+
+define <4 x i32> @t1() {
+ %tmp = xor <4 x i32> undef, undef
+ ret <4 x i32> %tmp
+}
+
+define i32 @t2() {
+ %tmp = xor i32 undef, undef
+ ret i32 %tmp
+}
More information about the llvm-commits
mailing list