[PATCH] D34699: [InstCombine] Propagate nsw flag when turning mul by pow2 into shift when the constant is a vector splat or the scalar bit width is larger than 64-bits
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 27 10:19:55 PDT 2017
craig.topper created this revision.
The check to see if we can propagate the nsw flag used m_ConstantInt(uint64_t*&) which doesn't work with splat vectors and has a restriction that the bitwidth of the ConstantInt must be 64-bits are less.
This patch changes it to use m_APInt to remove both these issues.
https://reviews.llvm.org/D34699
Files:
lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
test/Transforms/InstCombine/mul.ll
Index: test/Transforms/InstCombine/mul.ll
===================================================================
--- test/Transforms/InstCombine/mul.ll
+++ test/Transforms/InstCombine/mul.ll
@@ -300,7 +300,7 @@
define <2 x i32> @test32vec(<2 x i32> %X) {
; CHECK-LABEL: @test32vec(
-; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[X:%.*]], <i32 31, i32 31>
+; CHECK-NEXT: [[MUL:%.*]] = shl nsw <2 x i32> [[X:%.*]], <i32 31, i32 31>
; CHECK-NEXT: ret <2 x i32> [[MUL]]
;
%mul = mul nsw <2 x i32> %X, <i32 -2147483648, i32 -2147483648>
@@ -315,20 +315,18 @@
ret i32 %mul
}
-; TODO: we should propagate nsw flag to the shift here
define <2 x i32> @test33vec(<2 x i32> %X) {
; CHECK-LABEL: @test33vec(
-; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[X:%.*]], <i32 30, i32 30>
+; CHECK-NEXT: [[MUL:%.*]] = shl nsw <2 x i32> [[X:%.*]], <i32 30, i32 30>
; CHECK-NEXT: ret <2 x i32> [[MUL]]
;
%mul = mul nsw <2 x i32> %X, <i32 1073741824, i32 1073741824>
ret <2 x i32> %mul
}
-; TODO: we should propagate nsw flag to the shift here, but we only handle i64 and smaller
define i128 @test34(i128 %X) {
; CHECK-LABEL: @test34(
-; CHECK-NEXT: [[MUL:%.*]] = shl i128 [[X:%.*]], 1
+; CHECK-NEXT: [[MUL:%.*]] = shl nsw i128 [[X:%.*]], 1
; CHECK-NEXT: ret i128 [[MUL]]
;
%mul = mul nsw i128 %X, 2
Index: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -227,8 +227,8 @@
if (I.hasNoUnsignedWrap())
Shl->setHasNoUnsignedWrap();
if (I.hasNoSignedWrap()) {
- uint64_t V;
- if (match(NewCst, m_ConstantInt(V)) && V != Width - 1)
+ const APInt *V;
+ if (match(NewCst, m_APInt(V)) && *V != Width - 1)
Shl->setHasNoSignedWrap();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34699.104204.patch
Type: text/x-patch
Size: 1933 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170627/1f14acc1/attachment.bin>
More information about the llvm-commits
mailing list