mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-10 04:33:40 +00:00
Fix missed optimization opportunity when analyzing cast of mul and select.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53151 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
364d73ddab
commit
b8cd6a49b5
@ -6917,6 +6917,7 @@ bool InstCombiner::CanEvaluateInDifferentType(Value *V, const IntegerType *Ty,
|
|||||||
switch (I->getOpcode()) {
|
switch (I->getOpcode()) {
|
||||||
case Instruction::Add:
|
case Instruction::Add:
|
||||||
case Instruction::Sub:
|
case Instruction::Sub:
|
||||||
|
case Instruction::Mul:
|
||||||
case Instruction::And:
|
case Instruction::And:
|
||||||
case Instruction::Or:
|
case Instruction::Or:
|
||||||
case Instruction::Xor:
|
case Instruction::Xor:
|
||||||
@ -6926,14 +6927,6 @@ bool InstCombiner::CanEvaluateInDifferentType(Value *V, const IntegerType *Ty,
|
|||||||
CanEvaluateInDifferentType(I->getOperand(1), Ty, CastOpc,
|
CanEvaluateInDifferentType(I->getOperand(1), Ty, CastOpc,
|
||||||
NumCastsRemoved);
|
NumCastsRemoved);
|
||||||
|
|
||||||
case Instruction::Mul:
|
|
||||||
// A multiply can be truncated by truncating its operands.
|
|
||||||
return Ty->getBitWidth() < OrigTy->getBitWidth() &&
|
|
||||||
CanEvaluateInDifferentType(I->getOperand(0), Ty, CastOpc,
|
|
||||||
NumCastsRemoved) &&
|
|
||||||
CanEvaluateInDifferentType(I->getOperand(1), Ty, CastOpc,
|
|
||||||
NumCastsRemoved);
|
|
||||||
|
|
||||||
case Instruction::Shl:
|
case Instruction::Shl:
|
||||||
// If we are truncating the result of this SHL, and if it's a shift of a
|
// If we are truncating the result of this SHL, and if it's a shift of a
|
||||||
// constant amount, we can always perform a SHL in a smaller type.
|
// constant amount, we can always perform a SHL in a smaller type.
|
||||||
@ -6970,7 +6963,13 @@ bool InstCombiner::CanEvaluateInDifferentType(Value *V, const IntegerType *Ty,
|
|||||||
if (I->getOpcode() == CastOpc)
|
if (I->getOpcode() == CastOpc)
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
case Instruction::Select: {
|
||||||
|
SelectInst *SI = cast<SelectInst>(I);
|
||||||
|
return CanEvaluateInDifferentType(SI->getTrueValue(), Ty, CastOpc,
|
||||||
|
NumCastsRemoved) &&
|
||||||
|
CanEvaluateInDifferentType(SI->getFalseValue(), Ty, CastOpc,
|
||||||
|
NumCastsRemoved);
|
||||||
|
}
|
||||||
case Instruction::PHI: {
|
case Instruction::PHI: {
|
||||||
// We can change a phi if we can change all operands.
|
// We can change a phi if we can change all operands.
|
||||||
PHINode *PN = cast<PHINode>(I);
|
PHINode *PN = cast<PHINode>(I);
|
||||||
@ -7028,6 +7027,12 @@ Value *InstCombiner::EvaluateInDifferentType(Value *V, const Type *Ty,
|
|||||||
Res = CastInst::Create(cast<CastInst>(I)->getOpcode(), I->getOperand(0),
|
Res = CastInst::Create(cast<CastInst>(I)->getOpcode(), I->getOperand(0),
|
||||||
Ty);
|
Ty);
|
||||||
break;
|
break;
|
||||||
|
case Instruction::Select: {
|
||||||
|
Value *True = EvaluateInDifferentType(I->getOperand(1), Ty, isSigned);
|
||||||
|
Value *False = EvaluateInDifferentType(I->getOperand(2), Ty, isSigned);
|
||||||
|
Res = SelectInst::Create(I->getOperand(0), True, False);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case Instruction::PHI: {
|
case Instruction::PHI: {
|
||||||
PHINode *OPN = cast<PHINode>(I);
|
PHINode *OPN = cast<PHINode>(I);
|
||||||
PHINode *NPN = PHINode::Create(Ty);
|
PHINode *NPN = PHINode::Create(Ty);
|
||||||
|
29
test/Transforms/InstCombine/cast-mul-select.ll
Normal file
29
test/Transforms/InstCombine/cast-mul-select.ll
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | notcast
|
||||||
|
|
||||||
|
define i32 @mul(i32 %x, i32 %y) {
|
||||||
|
%A = trunc i32 %x to i8
|
||||||
|
%B = trunc i32 %y to i8
|
||||||
|
%C = mul i8 %A, %B
|
||||||
|
%D = zext i8 %C to i32
|
||||||
|
ret i32 %D
|
||||||
|
}
|
||||||
|
|
||||||
|
define i32 @select1(i1 %cond, i32 %x, i32 %y, i32 %z) {
|
||||||
|
%A = trunc i32 %x to i8
|
||||||
|
%B = trunc i32 %y to i8
|
||||||
|
%C = trunc i32 %z to i8
|
||||||
|
%D = add i8 %A, %B
|
||||||
|
%E = select i1 %cond, i8 %C, i8 %D
|
||||||
|
%F = zext i8 %E to i32
|
||||||
|
ret i32 %F
|
||||||
|
}
|
||||||
|
|
||||||
|
define i8 @select2(i1 %cond, i8 %x, i8 %y, i8 %z) {
|
||||||
|
%A = zext i8 %x to i32
|
||||||
|
%B = zext i8 %y to i32
|
||||||
|
%C = zext i8 %z to i32
|
||||||
|
%D = add i32 %A, %B
|
||||||
|
%E = select i1 %cond, i32 %C, i32 %D
|
||||||
|
%F = trunc i32 %E to i8
|
||||||
|
ret i8 %F
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user