From 7858cb9c0864f6d5e1335af080ec3f32f7cb64b3 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 19 Dec 2010 19:43:52 +0000 Subject: [PATCH] move a transformation to a more logical place, simplifying it. llvm-svn: 122183 --- lib/Transforms/InstCombine/InstCombineCalls.cpp | 16 ---------------- .../InstCombine/InstructionCombining.cpp | 7 +++++++ 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index f3a5e724c61..d53f3291e71 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -523,21 +523,6 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { return InsertValueInst::Create(Struct, Add, 0); } } - - // If the normal result of the add is dead, and the RHS is a constant, we - // can transform this into a range comparison. - // overflow = uadd a, -4 --> overflow = icmp ugt a, 3 - if (ConstantInt *CI = dyn_cast(RHS)) - if (ExtractValueInst *EVI = dyn_cast(II->use_back())) - if (II->hasOneUse() && EVI->getNumIndices() == 1 && !EVI->use_empty() && - *EVI->idx_begin() == 1) { // Extract of overflow result. - Builder->SetInsertPoint(EVI); - Value *R = Builder->CreateICmpUGT(LHS, ConstantExpr::getNot(CI)); - R->takeName(EVI); - ReplaceInstUsesWith(*EVI, R); - return II; - } - } // FALL THROUGH uadd into sadd case Intrinsic::sadd_with_overflow: @@ -565,7 +550,6 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { return InsertValueInst::Create(Struct, II->getArgOperand(0), 0); } } - break; case Intrinsic::usub_with_overflow: case Intrinsic::ssub_with_overflow: diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index b215ee817b1..5fa930e7541 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1147,6 +1147,13 @@ Instruction *InstCombiner::visitExtractValueInst(ExtractValueInst &EV) { EraseInstFromFunction(*II); return BinaryOperator::CreateAdd(LHS, RHS); } + + // If the normal result of the add is dead, and the RHS is a constant, + // we can transform this into a range comparison. + // overflow = uadd a, -4 --> overflow = icmp ugt a, 3 + if (ConstantInt *CI = dyn_cast(II->getArgOperand(1))) + return new ICmpInst(ICmpInst::ICMP_UGT, II->getArgOperand(0), + ConstantExpr::getNot(CI)); break; case Intrinsic::usub_with_overflow: case Intrinsic::ssub_with_overflow: