1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-22 04:22:57 +02:00
llvm-mirror/test/Transforms/Reassociate/wrap-flags.ll
Chad Rosier ac6f04f1d5 [Reassociate] Canonicalize negative constants out of expressions.
This is a reapplication of r221171, but we only perform the transformation
on expressions which include a multiplication.  We do not transform rem/div
operations as this doesn't appear to be safe in all cases.

llvm-svn: 221721
2014-11-11 22:58:35 +00:00

35 lines
772 B
LLVM

; 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: 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: 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: 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
}