diff options
author | Dan Gohman <gohman@apple.com> | 2009-10-26 22:14:22 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-10-26 22:14:22 +0000 |
commit | 672927f3934b51ade873e02d6ba1fc6e90c74548 (patch) | |
tree | 0231cbfdb0f769f3a0f1bd4056bb688bfb6484a2 /llvm | |
parent | 12e678d550258829920d0996a50bbc7f0e298e9f (diff) | |
download | bcm5719-llvm-672927f3934b51ade873e02d6ba1fc6e90c74548.tar.gz bcm5719-llvm-672927f3934b51ade873e02d6ba1fc6e90c74548.zip |
Code that checks WillNotOverflowSignedAdd before creating an Add
can safely use the NSW bit on the Add.
llvm-svn: 85164
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 16 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/add-shrink.ll | 2 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/add-sitofp.ll | 2 |
3 files changed, 10 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index a1d3c9736ef..7c0d22359fd 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -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()); } } diff --git a/llvm/test/Transforms/InstCombine/add-shrink.ll b/llvm/test/Transforms/InstCombine/add-shrink.ll index 52b8e327dba..cc574786631 100644 --- a/llvm/test/Transforms/InstCombine/add-shrink.ll +++ b/llvm/test/Transforms/InstCombine/add-shrink.ll @@ -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. diff --git a/llvm/test/Transforms/InstCombine/add-sitofp.ll b/llvm/test/Transforms/InstCombine/add-sitofp.ll index 24319df0b76..98a8cb452a6 100644 --- a/llvm/test/Transforms/InstCombine/add-sitofp.ll +++ b/llvm/test/Transforms/InstCombine/add-sitofp.ll @@ -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 |