forked from OSchip/llvm-project
Code that checks WillNotOverflowSignedAdd before creating an Add
can safely use the NSW bit on the Add. llvm-svn: 85164
This commit is contained in:
parent
12e678d550
commit
672927f393
|
@ -2420,8 +2420,8 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
|
|||
ConstantExpr::getSExt(CI, I.getType()) == RHSC &&
|
||||
WillNotOverflowSignedAdd(LHSConv->getOperand(0), CI)) {
|
||||
// Insert the new, smaller add.
|
||||
Value *NewAdd = Builder->CreateAdd(LHSConv->getOperand(0),
|
||||
CI, "addconv");
|
||||
Value *NewAdd = Builder->CreateNSWAdd(LHSConv->getOperand(0),
|
||||
CI, "addconv");
|
||||
return new SExtInst(NewAdd, I.getType());
|
||||
}
|
||||
}
|
||||
|
@ -2436,8 +2436,8 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
|
|||
WillNotOverflowSignedAdd(LHSConv->getOperand(0),
|
||||
RHSConv->getOperand(0))) {
|
||||
// Insert the new integer add.
|
||||
Value *NewAdd = Builder->CreateAdd(LHSConv->getOperand(0),
|
||||
RHSConv->getOperand(0), "addconv");
|
||||
Value *NewAdd = Builder->CreateNSWAdd(LHSConv->getOperand(0),
|
||||
RHSConv->getOperand(0), "addconv");
|
||||
return new SExtInst(NewAdd, I.getType());
|
||||
}
|
||||
}
|
||||
|
@ -2493,8 +2493,8 @@ Instruction *InstCombiner::visitFAdd(BinaryOperator &I) {
|
|||
ConstantExpr::getSIToFP(CI, I.getType()) == CFP &&
|
||||
WillNotOverflowSignedAdd(LHSConv->getOperand(0), CI)) {
|
||||
// Insert the new integer add.
|
||||
Value *NewAdd = Builder->CreateAdd(LHSConv->getOperand(0),
|
||||
CI, "addconv");
|
||||
Value *NewAdd = Builder->CreateNSWAdd(LHSConv->getOperand(0),
|
||||
CI, "addconv");
|
||||
return new SIToFPInst(NewAdd, I.getType());
|
||||
}
|
||||
}
|
||||
|
@ -2509,8 +2509,8 @@ Instruction *InstCombiner::visitFAdd(BinaryOperator &I) {
|
|||
WillNotOverflowSignedAdd(LHSConv->getOperand(0),
|
||||
RHSConv->getOperand(0))) {
|
||||
// Insert the new integer add.
|
||||
Value *NewAdd = Builder->CreateAdd(LHSConv->getOperand(0),
|
||||
RHSConv->getOperand(0), "addconv");
|
||||
Value *NewAdd = Builder->CreateNSWAdd(LHSConv->getOperand(0),
|
||||
RHSConv->getOperand(0), "addconv");
|
||||
return new SIToFPInst(NewAdd, I.getType());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
; RUN: opt < %s -instcombine -S | grep {add i32}
|
||||
; RUN: opt < %s -instcombine -S | grep {add nsw i32}
|
||||
; RUN: opt < %s -instcombine -S | grep sext | count 1
|
||||
|
||||
; Should only have one sext and the add should be i32 instead of i64.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
; RUN: opt < %s -instcombine -S | grep {add i32}
|
||||
; RUN: opt < %s -instcombine -S | grep {add nsw i32}
|
||||
|
||||
define double @x(i32 %a, i32 %b) nounwind {
|
||||
%m = lshr i32 %a, 24
|
||||
|
|
Loading…
Reference in New Issue