mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-26 05:25:47 +00:00
Teach the transformation that moves binary operators around selects to preserve
the subclass optional data. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128388 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -214,7 +214,7 @@ Instruction *InstCombiner::FoldSelectIntoOp(SelectInst &SI, Value *TrueVal,
|
|||||||
unsigned OpToFold = 0;
|
unsigned OpToFold = 0;
|
||||||
if ((SFO & 1) && FalseVal == TVI->getOperand(0)) {
|
if ((SFO & 1) && FalseVal == TVI->getOperand(0)) {
|
||||||
OpToFold = 1;
|
OpToFold = 1;
|
||||||
} else if ((SFO & 2) && FalseVal == TVI->getOperand(1)) {
|
} else if ((SFO & 2) && FalseVal == TVI->getOperand(1)) {
|
||||||
OpToFold = 2;
|
OpToFold = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,9 +227,16 @@ Instruction *InstCombiner::FoldSelectIntoOp(SelectInst &SI, Value *TrueVal,
|
|||||||
Instruction *NewSel = SelectInst::Create(SI.getCondition(), OOp, C);
|
Instruction *NewSel = SelectInst::Create(SI.getCondition(), OOp, C);
|
||||||
InsertNewInstBefore(NewSel, SI);
|
InsertNewInstBefore(NewSel, SI);
|
||||||
NewSel->takeName(TVI);
|
NewSel->takeName(TVI);
|
||||||
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(TVI))
|
BinaryOperator *TVI_BO = cast<BinaryOperator>(TVI);
|
||||||
return BinaryOperator::Create(BO->getOpcode(), FalseVal, NewSel);
|
BinaryOperator *BO = BinaryOperator::Create(TVI_BO->getOpcode(),
|
||||||
llvm_unreachable("Unknown instruction!!");
|
FalseVal, NewSel);
|
||||||
|
if (isa<PossiblyExactOperator>(BO))
|
||||||
|
BO->setIsExact(TVI_BO->isExact());
|
||||||
|
if (isa<OverflowingBinaryOperator>(BO)) {
|
||||||
|
BO->setHasNoUnsignedWrap(TVI_BO->hasNoUnsignedWrap());
|
||||||
|
BO->setHasNoSignedWrap(TVI_BO->hasNoSignedWrap());
|
||||||
|
}
|
||||||
|
return BO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -243,7 +250,7 @@ Instruction *InstCombiner::FoldSelectIntoOp(SelectInst &SI, Value *TrueVal,
|
|||||||
unsigned OpToFold = 0;
|
unsigned OpToFold = 0;
|
||||||
if ((SFO & 1) && TrueVal == FVI->getOperand(0)) {
|
if ((SFO & 1) && TrueVal == FVI->getOperand(0)) {
|
||||||
OpToFold = 1;
|
OpToFold = 1;
|
||||||
} else if ((SFO & 2) && TrueVal == FVI->getOperand(1)) {
|
} else if ((SFO & 2) && TrueVal == FVI->getOperand(1)) {
|
||||||
OpToFold = 2;
|
OpToFold = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,9 +263,16 @@ Instruction *InstCombiner::FoldSelectIntoOp(SelectInst &SI, Value *TrueVal,
|
|||||||
Instruction *NewSel = SelectInst::Create(SI.getCondition(), C, OOp);
|
Instruction *NewSel = SelectInst::Create(SI.getCondition(), C, OOp);
|
||||||
InsertNewInstBefore(NewSel, SI);
|
InsertNewInstBefore(NewSel, SI);
|
||||||
NewSel->takeName(FVI);
|
NewSel->takeName(FVI);
|
||||||
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(FVI))
|
BinaryOperator *FVI_BO = cast<BinaryOperator>(FVI);
|
||||||
return BinaryOperator::Create(BO->getOpcode(), TrueVal, NewSel);
|
BinaryOperator *BO = BinaryOperator::Create(FVI_BO->getOpcode(),
|
||||||
llvm_unreachable("Unknown instruction!!");
|
TrueVal, NewSel);
|
||||||
|
if (isa<PossiblyExactOperator>(BO))
|
||||||
|
BO->setIsExact(FVI_BO->isExact());
|
||||||
|
if (isa<OverflowingBinaryOperator>(BO)) {
|
||||||
|
BO->setHasNoUnsignedWrap(FVI_BO->hasNoUnsignedWrap());
|
||||||
|
BO->setHasNoSignedWrap(FVI_BO->hasNoSignedWrap());
|
||||||
|
}
|
||||||
|
return BO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -737,3 +737,15 @@ define i32 @test54(i32 %X, i32 %Y) {
|
|||||||
; CHECK: zext
|
; CHECK: zext
|
||||||
; CHECK: ret
|
; CHECK: ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define i1 @test55(i1 %X, i32 %Y, i32 %Z) {
|
||||||
|
%A = ashr exact i32 %Y, %Z
|
||||||
|
%B = select i1 %X, i32 %Y, i32 %A
|
||||||
|
%C = icmp eq i32 %B, 0
|
||||||
|
ret i1 %C
|
||||||
|
; CHECK: @test55
|
||||||
|
; CHECK-NOT: ashr
|
||||||
|
; CHECK-NOT: select
|
||||||
|
; CHECK: icmp eq
|
||||||
|
; CHECK: ret i1
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user