[llvm] r293706 - NewGVN: Add basic support for symbolic comparison evaluation
Daniel Berlin via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 31 14:31:58 PST 2017
Author: dannyb
Date: Tue Jan 31 16:31:58 2017
New Revision: 293706
URL: http://llvm.org/viewvc/llvm-project?rev=293706&view=rev
Log:
NewGVN: Add basic support for symbolic comparison evaluation
Modified:
llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp?rev=293706&r1=293705&r2=293706&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp Tue Jan 31 16:31:58 2017
@@ -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::performSymbolicAggrValueEvaluati
return createAggregateValueExpression(I, B);
}
+const Expression *NewGVN::performSymbolicCmpEvaluation(Instruction *I,
+ const BasicBlock *B) {
+ CmpInst *CI = dyn_cast<CmpInst>(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::performSymboli
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::performSymboli
case Instruction::And:
case Instruction::Or:
case Instruction::Xor:
- case Instruction::ICmp:
- case Instruction::FCmp:
case Instruction::Trunc:
case Instruction::ZExt:
case Instruction::SExt:
More information about the llvm-commits
mailing list