mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-25 12:04:36 +00:00
fix rdar://9297006 - fast isel bails out on trunc to i1 -> bools cry,
a common cause of fast isel rejects on c++ code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129748 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
75b41f1540
commit
90cb88a9b4
@ -865,12 +865,9 @@ bool X86FastISel::X86SelectCmp(const Instruction *I) {
|
||||
|
||||
unsigned NEReg = createResultReg(&X86::GR8RegClass);
|
||||
unsigned PReg = createResultReg(&X86::GR8RegClass);
|
||||
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
||||
TII.get(X86::SETNEr), NEReg);
|
||||
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
||||
TII.get(X86::SETPr), PReg);
|
||||
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
||||
TII.get(X86::OR8rr), ResultReg)
|
||||
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(X86::SETNEr), NEReg);
|
||||
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(X86::SETPr), PReg);
|
||||
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(X86::OR8rr),ResultReg)
|
||||
.addReg(PReg).addReg(NEReg);
|
||||
UpdateValueMap(I, ResultReg);
|
||||
return true;
|
||||
@ -1068,6 +1065,32 @@ bool X86FastISel::X86SelectBranch(const Instruction *I) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (TruncInst *TI = dyn_cast<TruncInst>(BI->getCondition())) {
|
||||
// Handle things like "%cond = trunc i32 %X to i1 / br i1 %cond", which
|
||||
// typically happen for _Bool and C++ bools.
|
||||
MVT SourceVT;
|
||||
if (TI->hasOneUse() && TI->getParent() == I->getParent() &&
|
||||
isTypeLegal(TI->getOperand(0)->getType(), SourceVT)) {
|
||||
unsigned TestOpc = 0;
|
||||
switch (SourceVT.SimpleTy) {
|
||||
default: break;
|
||||
case MVT::i8: TestOpc = X86::TEST8ri; break;
|
||||
case MVT::i16: TestOpc = X86::TEST16ri; break;
|
||||
case MVT::i32: TestOpc = X86::TEST32ri; break;
|
||||
case MVT::i64: TestOpc = X86::TEST64ri32; break;
|
||||
}
|
||||
if (TestOpc) {
|
||||
unsigned OpReg = getRegForValue(TI->getOperand(0));
|
||||
if (OpReg == 0) return false;
|
||||
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TestOpc))
|
||||
.addReg(OpReg).addImm(1);
|
||||
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(X86::JNE_4))
|
||||
.addMBB(TrueMBB);
|
||||
FastEmitBranch(FalseMBB, DL);
|
||||
FuncInfo.MBB->addSuccessor(TrueMBB);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise do a clumsy setcc and re-test it.
|
||||
|
@ -127,3 +127,20 @@ define i32 @test11(i32 %X) nounwind {
|
||||
; CHECK: sarl $3,
|
||||
}
|
||||
|
||||
|
||||
; rdar://9297006 - Trunc to bool.
|
||||
define void @test12(i8 %tmp) nounwind ssp noredzone {
|
||||
entry:
|
||||
%tobool = trunc i8 %tmp to i1
|
||||
br i1 %tobool, label %if.then, label %if.end
|
||||
|
||||
if.then: ; preds = %entry
|
||||
call void @test12(i8 0) noredzone
|
||||
br label %if.end
|
||||
|
||||
if.end: ; preds = %if.then, %entry
|
||||
ret void
|
||||
; CHECK: test12:
|
||||
; CHECK: testb $1,
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user