diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-02-02 22:43:55 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-02-02 22:43:55 +0000 |
commit | 1ff08e389f82561659945bab8a55bdba5fc8e9dc (patch) | |
tree | e86d6a986a6849f27e9b310de4fb31c9e0d6ddce /llvm/lib | |
parent | d11c478ac31d1c7c028d9a07c8eda168ef49a744 (diff) | |
download | bcm5719-llvm-1ff08e389f82561659945bab8a55bdba5fc8e9dc.tar.gz bcm5719-llvm-1ff08e389f82561659945bab8a55bdba5fc8e9dc.zip |
Lower llvm.expect intrinsic correctly for i1
LowerExpectIntrinsic previously only understood the idiom of an expect
intrinsic followed by a comparison with zero. For llvm.expect.i1, the
comparison would be stripped by the early-cse pass.
Patch by Daniel Micay.
llvm-svn: 200664
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Utils/LowerExpectIntrinsic.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/LowerExpectIntrinsic.cpp b/llvm/lib/Transforms/Utils/LowerExpectIntrinsic.cpp index e017f501209..596fd371151 100644 --- a/llvm/lib/Transforms/Utils/LowerExpectIntrinsic.cpp +++ b/llvm/lib/Transforms/Utils/LowerExpectIntrinsic.cpp @@ -94,15 +94,25 @@ bool LowerExpectIntrinsic::HandleIfExpect(BranchInst *BI) { return false; // Handle non-optimized IR code like: - // %expval = call i64 @llvm.expect.i64.i64(i64 %conv1, i64 1) + // %expval = call i64 @llvm.expect.i64(i64 %conv1, i64 1) // %tobool = icmp ne i64 %expval, 0 // br i1 %tobool, label %if.then, label %if.end + // + // Or the following simpler case: + // %expval = call i1 @llvm.expect.i1(i1 %cmp, i1 1) + // br i1 %expval, label %if.then, label %if.end + + CallInst *CI; ICmpInst *CmpI = dyn_cast<ICmpInst>(BI->getCondition()); - if (!CmpI || CmpI->getPredicate() != CmpInst::ICMP_NE) - return false; + if (!CmpI) { + CI = dyn_cast<CallInst>(BI->getCondition()); + } else { + if (CmpI->getPredicate() != CmpInst::ICMP_NE) + return false; + CI = dyn_cast<CallInst>(CmpI->getOperand(0)); + } - CallInst *CI = dyn_cast<CallInst>(CmpI->getOperand(0)); if (!CI) return false; @@ -127,7 +137,10 @@ bool LowerExpectIntrinsic::HandleIfExpect(BranchInst *BI) { BI->setMetadata(LLVMContext::MD_prof, Node); - CmpI->setOperand(0, ArgValue); + if (CmpI) + CmpI->setOperand(0, ArgValue); + else + BI->setCondition(ArgValue); return true; } |