Changeset View
Changeset View
Standalone View
Standalone View
lib/Transforms/Scalar/NewGVN.cpp
Show First 20 Lines • Show All 1,160 Lines • ▼ Show 20 Lines | if (isa<Constant>(E->getOperand(0)) || | ||||
if (const Expression *SimplifiedE = checkSimplificationResults(E, I, V)) | if (const Expression *SimplifiedE = checkSimplificationResults(E, I, V)) | ||||
return SimplifiedE; | return SimplifiedE; | ||||
} | } | ||||
} else if (I->isBinaryOp()) { | } else if (I->isBinaryOp()) { | ||||
Value *V = | Value *V = | ||||
SimplifyBinOp(E->getOpcode(), E->getOperand(0), E->getOperand(1), SQ); | SimplifyBinOp(E->getOpcode(), E->getOperand(0), E->getOperand(1), SQ); | ||||
if (const Expression *SimplifiedE = checkSimplificationResults(E, I, V)) | if (const Expression *SimplifiedE = checkSimplificationResults(E, I, V)) | ||||
return SimplifiedE; | return SimplifiedE; | ||||
} else if (auto *BI = dyn_cast<BitCastInst>(I)) { | } else if (auto *CI = dyn_cast<CastInst>(I)) { | ||||
Value *V = | Value *V = | ||||
SimplifyCastInst(BI->getOpcode(), BI->getOperand(0), BI->getType(), SQ); | SimplifyCastInst(CI->getOpcode(), E->getOperand(0), CI->getType(), SQ); | ||||
fhahn: The code here should pass in `E->getOperand(0)`, instead of `CI->getOperand(0)`: we want to… | |||||
if (const Expression *SimplifiedE = checkSimplificationResults(E, I, V)) | if (const Expression *SimplifiedE = checkSimplificationResults(E, I, V)) | ||||
return SimplifiedE; | return SimplifiedE; | ||||
} else if (isa<GetElementPtrInst>(I)) { | } else if (isa<GetElementPtrInst>(I)) { | ||||
Value *V = SimplifyGEPInst( | Value *V = SimplifyGEPInst( | ||||
E->getType(), ArrayRef<Value *>(E->op_begin(), E->op_end()), SQ); | E->getType(), ArrayRef<Value *>(E->op_begin(), E->op_end()), SQ); | ||||
if (const Expression *SimplifiedE = checkSimplificationResults(E, I, V)) | if (const Expression *SimplifiedE = checkSimplificationResults(E, I, V)) | ||||
return SimplifiedE; | return SimplifiedE; | ||||
} else if (AllConstant) { | } else if (AllConstant) { | ||||
// We don't bother trying to simplify unless all of the operands | // We don't bother trying to simplify unless all of the operands | ||||
// were constant. | // were constant. | ||||
Not Done ReplyInline ActionsThe way I understand this: If you have a BitCast, or maybe even another instruction, for which the simplify failed but AllConstant is true, you won't get constant folding before, correct? Would it be possible to show the problem even w/o AddrSpaceCast? jdoerfert: The way I understand this: If you have a BitCast, or maybe even another instruction, for which… | |||||
// TODO: There are a lot of Simplify*'s we could call here, if we | // TODO: There are a lot of Simplify*'s we could call here, if we | ||||
// wanted to. The original motivating case for this code was a | // wanted to. The original motivating case for this code was a | ||||
// zext i1 false to i8, which we don't have an interface to | // zext i1 false to i8, which we don't have an interface to | ||||
// simplify (IE there is no SimplifyZExt). | // simplify (IE there is no SimplifyZExt). | ||||
SmallVector<Constant *, 8> C; | SmallVector<Constant *, 8> C; | ||||
for (Value *Arg : E->operands()) | for (Value *Arg : E->operands()) | ||||
C.emplace_back(cast<Constant>(Arg)); | C.emplace_back(cast<Constant>(Arg)); | ||||
▲ Show 20 Lines • Show All 789 Lines • ▼ Show 20 Lines | case Instruction::Call: | ||||
break; | break; | ||||
case Instruction::Store: | case Instruction::Store: | ||||
E = performSymbolicStoreEvaluation(I); | E = performSymbolicStoreEvaluation(I); | ||||
break; | break; | ||||
case Instruction::Load: | case Instruction::Load: | ||||
E = performSymbolicLoadEvaluation(I); | E = performSymbolicLoadEvaluation(I); | ||||
break; | break; | ||||
case Instruction::BitCast: | case Instruction::BitCast: | ||||
case Instruction::AddrSpaceCast: | |||||
E = createExpression(I); | E = createExpression(I); | ||||
break; | break; | ||||
case Instruction::ICmp: | case Instruction::ICmp: | ||||
case Instruction::FCmp: | case Instruction::FCmp: | ||||
E = performSymbolicCmpEvaluation(I); | E = performSymbolicCmpEvaluation(I); | ||||
break; | break; | ||||
case Instruction::Add: | case Instruction::Add: | ||||
case Instruction::FAdd: | case Instruction::FAdd: | ||||
▲ Show 20 Lines • Show All 2,248 Lines • Show Last 20 Lines |
The code here should pass in E->getOperand(0), instead of CI->getOperand(0): we want to pass in the leader for the operand, not the operand from the original IR. This way, there should be no need to move the AllConstant condition. If the leader of the CastInst is constant, we should already simplify it here.
Please note that there is a subtle underlying issue with the way simplifications on the original IR and the simplified leaders interact, but that needs to be addressed separately and I do not think CastInst should have any special treatment here. If anything, it may make it a bit harder to trigger the issue.