[llvm-commits] [llvm] r152884 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp test/Transforms/InstCombine/2012-3-15-or-xor-constant.ll

Eli Friedman eli.friedman at gmail.com
Thu Mar 15 17:52:42 PDT 2012


Author: efriedma
Date: Thu Mar 15 19:52:42 2012
New Revision: 152884

URL: http://llvm.org/viewvc/llvm-project?rev=152884&view=rev
Log:
In InstCombiner::visitOr, make sure we reverse the operand swap used for checking for or-of-xor operations after those checks; a later check expects that any constant will be in Op1.  PR12234.


Added:
    llvm/trunk/test/Transforms/InstCombine/2012-3-15-or-xor-constant.ll
Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=152884&r1=152883&r2=152884&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Thu Mar 15 19:52:42 2012
@@ -1929,8 +1929,11 @@
       }
 
   // Canonicalize xor to the RHS.
-  if (match(Op0, m_Xor(m_Value(), m_Value())))
+  bool SwappedForXor = false;
+  if (match(Op0, m_Xor(m_Value(), m_Value()))) {
     std::swap(Op0, Op1);
+    SwappedForXor = true;
+  }
 
   // A | ( A ^ B) -> A |  B
   // A | (~A ^ B) -> A | ~B
@@ -1961,6 +1964,9 @@
         return BinaryOperator::CreateOr(Not, Op0);
       }
 
+  if (SwappedForXor)
+    std::swap(Op0, Op1);
+
   if (ICmpInst *RHS = dyn_cast<ICmpInst>(I.getOperand(1)))
     if (ICmpInst *LHS = dyn_cast<ICmpInst>(I.getOperand(0)))
       if (Value *Res = FoldOrOfICmps(LHS, RHS))

Added: llvm/trunk/test/Transforms/InstCombine/2012-3-15-or-xor-constant.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2012-3-15-or-xor-constant.ll?rev=152884&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2012-3-15-or-xor-constant.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/2012-3-15-or-xor-constant.ll Thu Mar 15 19:52:42 2012
@@ -0,0 +1,12 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+; PR12234
+
+ at g = extern_weak global i32
+define i32 @function(i32 %x) nounwind {
+entry:
+  %xor = xor i32 %x, 1
+  store volatile i32 %xor, i32* inttoptr (i64 1 to i32*), align 4
+  %or4 = or i32 or (i32 zext (i1 icmp eq (i32* @g, i32* null) to i32), i32 1), %xor
+  ret i32 %or4
+}
+; CHECK: define i32 @function





More information about the llvm-commits mailing list