From f7f430c9136330545637aaddebf013da05c0f370 Mon Sep 17 00:00:00 2001 From: Stanislav Mekhanoshin Date: Thu, 28 Oct 2021 12:14:02 -0700 Subject: [PATCH] [InstCombine] Fixed non-determinisctic order of new instructions Fixes non-determinisctic order of XOR instructions created after 5a7a458306cd. The order of call argument evaluation is not defined, so create one Value before the call. --- llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 5ef1145..ac79e21 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2805,15 +2805,17 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) { m_Value(C))))) { if (match(Op1, m_OneUse(m_c_And( m_OneUse(m_Not(m_c_Or(m_Specific(A), m_Specific(C)))), - m_Specific(B))))) - return BinaryOperator::CreateAnd(Builder.CreateXor(B, C), - Builder.CreateNot(A)); + m_Specific(B))))) { + Value *Xor = Builder.CreateXor(B, C); + return BinaryOperator::CreateAnd(Xor, Builder.CreateNot(A)); + } if (match(Op1, m_OneUse(m_c_And( m_OneUse(m_Not(m_c_Or(m_Specific(B), m_Specific(C)))), - m_Specific(A))))) - return BinaryOperator::CreateAnd(Builder.CreateXor(A, C), - Builder.CreateNot(B)); + m_Specific(A))))) { + Value *Xor = Builder.CreateXor(A, C); + return BinaryOperator::CreateAnd(Xor, Builder.CreateNot(B)); + } } if (Instruction *DeMorgan = matchDeMorgansLaws(I, Builder)) -- 2.7.4