Skip to content

Commit 5fe0197

Browse files
committedJun 27, 2017
[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
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 Differential Revision: https://reviews.llvm.org/D34699 llvm-svn: 306457
1 parent ccbb810 commit 5fe0197

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed
 

‎llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
227227
if (I.hasNoUnsignedWrap())
228228
Shl->setHasNoUnsignedWrap();
229229
if (I.hasNoSignedWrap()) {
230-
uint64_t V;
231-
if (match(NewCst, m_ConstantInt(V)) && V != Width - 1)
230+
const APInt *V;
231+
if (match(NewCst, m_APInt(V)) && *V != Width - 1)
232232
Shl->setHasNoSignedWrap();
233233
}
234234

‎llvm/test/Transforms/InstCombine/mul.ll

+3-5
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ define i32 @test32(i32 %X) {
300300

301301
define <2 x i32> @test32vec(<2 x i32> %X) {
302302
; CHECK-LABEL: @test32vec(
303-
; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[X:%.*]], <i32 31, i32 31>
303+
; CHECK-NEXT: [[MUL:%.*]] = shl nsw <2 x i32> [[X:%.*]], <i32 31, i32 31>
304304
; CHECK-NEXT: ret <2 x i32> [[MUL]]
305305
;
306306
%mul = mul nsw <2 x i32> %X, <i32 -2147483648, i32 -2147483648>
@@ -315,20 +315,18 @@ define i32 @test33(i32 %X) {
315315
ret i32 %mul
316316
}
317317

318-
; TODO: we should propagate nsw flag to the shift here
319318
define <2 x i32> @test33vec(<2 x i32> %X) {
320319
; CHECK-LABEL: @test33vec(
321-
; CHECK-NEXT: [[MUL:%.*]] = shl <2 x i32> [[X:%.*]], <i32 30, i32 30>
320+
; CHECK-NEXT: [[MUL:%.*]] = shl nsw <2 x i32> [[X:%.*]], <i32 30, i32 30>
322321
; CHECK-NEXT: ret <2 x i32> [[MUL]]
323322
;
324323
%mul = mul nsw <2 x i32> %X, <i32 1073741824, i32 1073741824>
325324
ret <2 x i32> %mul
326325
}
327326

328-
; TODO: we should propagate nsw flag to the shift here, but we only handle i64 and smaller
329327
define i128 @test34(i128 %X) {
330328
; CHECK-LABEL: @test34(
331-
; CHECK-NEXT: [[MUL:%.*]] = shl i128 [[X:%.*]], 1
329+
; CHECK-NEXT: [[MUL:%.*]] = shl nsw i128 [[X:%.*]], 1
332330
; CHECK-NEXT: ret i128 [[MUL]]
333331
;
334332
%mul = mul nsw i128 %X, 2

0 commit comments

Comments
 (0)
Please sign in to comment.