summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/Reassociate
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@codeaurora.org>2014-11-07 22:12:57 +0000
committerChad Rosier <mcrosier@codeaurora.org>2014-11-07 22:12:57 +0000
commitb3eb452e83cf56d52081c969155208d979d106a1 (patch)
treede98ac55bb10d06d00a61774304782928961e556 /llvm/test/Transforms/Reassociate
parent89c5ad4cda7356a4da124c41f69fd3e002609681 (diff)
downloadbcm5719-llvm-b3eb452e83cf56d52081c969155208d979d106a1.tar.gz
bcm5719-llvm-b3eb452e83cf56d52081c969155208d979d106a1.zip
[Reassociate] Better preserve NSW/NUW flags.
Part of PR12985. Phabricator Revision: http://reviews.llvm.org/D6172 llvm-svn: 221555
Diffstat (limited to 'llvm/test/Transforms/Reassociate')
-rw-r--r--llvm/test/Transforms/Reassociate/wrap-flags.ll34
1 files changed, 34 insertions, 0 deletions
diff --git a/llvm/test/Transforms/Reassociate/wrap-flags.ll b/llvm/test/Transforms/Reassociate/wrap-flags.ll
new file mode 100644
index 00000000000..7483acd02e5
--- /dev/null
+++ b/llvm/test/Transforms/Reassociate/wrap-flags.ll
@@ -0,0 +1,34 @@
+; RUN: opt < %s -reassociate -dce -S | FileCheck %s
+; PR12985
+
+; Verify the nsw flags are preserved when converting shl to mul.
+
+; CHECK-LABEL: @shl_to_mul_nsw(
+; CHECK: %mul = mul i32 %i, -2147483648
+; CHECK: %mul2 = add i32 %mul, 1
+define i32 @shl_to_mul_nsw(i32 %i) {
+entry:
+ %mul = shl nsw i32 %i, 31
+ %mul2 = add i32 %mul, 1
+ ret i32 %mul2
+}
+
+; CHECK-LABEL: @shl_to_mul_nuw(
+; CHECK: %mul = mul nuw i32 %i, 4
+; CHECK: %mul2 = add i32 %mul, 1
+define i32 @shl_to_mul_nuw(i32 %i) {
+entry:
+ %mul = shl nuw i32 %i, 2
+ %mul2 = add i32 %mul, 1
+ ret i32 %mul2
+}
+
+; CHECK-LABEL: @shl_to_mul_nuw_nsw(
+; CHECK: %mul = mul nuw nsw i32 %i, 4
+; CHECK: %mul2 = add i32 %mul, 1
+define i32 @shl_to_mul_nuw_nsw(i32 %i) {
+entry:
+ %mul = shl nuw nsw i32 %i, 2
+ %mul2 = add i32 %mul, 1
+ ret i32 %mul2
+}
OpenPOWER on IntegriCloud