From 28b84ff4cec5bf2de4c1f85b85d613818175c4d4 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Sun, 14 Aug 2011 04:51:49 +0000 Subject: [PATCH] This transform is not safe. Thanks to Eli for pointing that out! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@137575 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../InstCombine/InstructionCombining.cpp | 9 +-------- test/Transforms/InstCombine/nsw.ll | 20 +++++++++---------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index 41666361141..41d542af685 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -294,14 +294,7 @@ bool InstCombiner::SimplifyAssociativeOrCommutative(BinaryOperator &I) { I.setOperand(1, Folded); // Conservatively clear the optional flags, since they may not be // preserved by the reassociation. - if (MaintainNoSignedWrap(I, C1, C2) && Op0->hasNoSignedWrap() && - Op1->hasNoSignedWrap()) { - New->setHasNoSignedWrap(true); - I.clearSubclassOptionalData(); - I.setHasNoSignedWrap(true); - } else { - I.clearSubclassOptionalData(); - } + I.clearSubclassOptionalData(); Changed = true; continue; diff --git a/test/Transforms/InstCombine/nsw.ll b/test/Transforms/InstCombine/nsw.ll index 0e715075fc3..0140c2f8012 100644 --- a/test/Transforms/InstCombine/nsw.ll +++ b/test/Transforms/InstCombine/nsw.ll @@ -46,16 +46,6 @@ define i32 @preserve1(i32 %x) nounwind { ret i32 %add3 } -; CHECK: @preserve2 -; CHECK: add nsw i8 %A, %B -; CHECK: add nsw i8 -define i8 @preserve2(i8 %A, i8 %B) nounwind { - %x = add nsw i8 %A, 10 - %y = add nsw i8 %B, 10 - %add = add nsw i8 %x, %y - ret i8 %add -} - ; CHECK: @nopreserve1 ; CHECK: add i8 %x, -126 define i8 @nopreserve1(i8 %x) nounwind { @@ -81,3 +71,13 @@ define i8 @nopreserve3(i8 %A, i8 %B) nounwind { %add = add nsw i8 %x, %y ret i8 %add } + +; CHECK: @nopreserve4 +; CHECK: add i8 %A, %B +; CHECK: add i8 +define i8 @nopreserve4(i8 %A, i8 %B) nounwind { + %x = add nsw i8 %A, 10 + %y = add nsw i8 %B, 10 + %add = add nsw i8 %x, %y + ret i8 %add +}