mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-12 13:38:21 +00:00
[InstCombine] Fix visitSwitchInst to use right operand types for sub cstexpr
The visitSwitchInst generates SUB constant expressions to recompute the switch condition. When truncating the condition to a smaller type, SUB expressions should use the previous type (before trunc) for both operands. This fixes an assertion crash. Differential Revision: http://reviews.llvm.org/D6644 rdar://problem/19191835 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224574 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -2115,8 +2115,10 @@ Instruction *InstCombiner::visitSwitchInst(SwitchInst &SI) {
|
||||
for (SwitchInst::CaseIt i = SI.case_begin(), e = SI.case_end();
|
||||
i != e; ++i) {
|
||||
ConstantInt* CaseVal = i.getCaseValue();
|
||||
Constant* NewCaseVal = ConstantExpr::getSub(cast<Constant>(CaseVal),
|
||||
AddRHS);
|
||||
Constant *LHS = LeadingKnownZeros
|
||||
? ConstantExpr::getZExt(CaseVal, Cond->getType())
|
||||
: ConstantExpr::getSExt(CaseVal, Cond->getType());
|
||||
Constant* NewCaseVal = ConstantExpr::getSub(LHS, AddRHS);
|
||||
assert(isa<ConstantInt>(NewCaseVal) &&
|
||||
"Result of expression should be constant");
|
||||
i.setValue(cast<ConstantInt>(NewCaseVal));
|
||||
|
Reference in New Issue
Block a user