From: Daniel Berlin Date: Tue, 31 Jan 2017 22:31:58 +0000 (+0000) Subject: NewGVN: Add basic support for symbolic comparison evaluation X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=05b6b111d2794f9cbd7f9a55f8451573ef3f4b06;p=llvm NewGVN: Add basic support for symbolic comparison evaluation git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293706 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/NewGVN.cpp b/lib/Transforms/Scalar/NewGVN.cpp index 37c09fa5605..7a0e076abfc 100644 --- a/lib/Transforms/Scalar/NewGVN.cpp +++ b/lib/Transforms/Scalar/NewGVN.cpp @@ -347,6 +347,8 @@ private: const BasicBlock *); const Expression *performSymbolicAggrValueEvaluation(Instruction *, const BasicBlock *); + const Expression *performSymbolicCmpEvaluation(Instruction *, + const BasicBlock *); // Congruence finding. Value *lookupOperandLeader(Value *) const; @@ -1002,6 +1004,20 @@ NewGVN::performSymbolicAggrValueEvaluation(Instruction *I, return createAggregateValueExpression(I, B); } +const Expression *NewGVN::performSymbolicCmpEvaluation(Instruction *I, + const BasicBlock *B) { + CmpInst *CI = dyn_cast(I); + // See if our operands are equal and that implies something. + auto Op0 = lookupOperandLeader(CI->getOperand(0)); + auto Op1 = lookupOperandLeader(CI->getOperand(1)); + if (Op0 == Op1) { + if (CI->isTrueWhenEqual()) + return createConstantExpression(ConstantInt::getTrue(CI->getType())); + else if (CI->isFalseWhenEqual()) + return createConstantExpression(ConstantInt::getFalse(CI->getType())); + } + return createExpression(I, B); +} // Substitute and symbolize the value before value numbering. const Expression *NewGVN::performSymbolicEvaluation(Value *V, @@ -1036,7 +1052,10 @@ const Expression *NewGVN::performSymbolicEvaluation(Value *V, case Instruction::BitCast: { E = createExpression(I, B); } break; - + case Instruction::ICmp: + case Instruction::FCmp: { + E = performSymbolicCmpEvaluation(I, B); + } break; case Instruction::Add: case Instruction::FAdd: case Instruction::Sub: @@ -1055,8 +1074,6 @@ const Expression *NewGVN::performSymbolicEvaluation(Value *V, case Instruction::And: case Instruction::Or: case Instruction::Xor: - case Instruction::ICmp: - case Instruction::FCmp: case Instruction::Trunc: case Instruction::ZExt: case Instruction::SExt: