From a24f1373602b68b8dd44a7404fd2e68198bc56e5 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 20 Apr 2017 21:33:02 +0000 Subject: [PATCH] [InstCombine] allow shl demanded bits folds with splat constants More fixes are needed to enable the helper SimplifyShrShlDemandedBits(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300898 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | 6 ++++-- test/Transforms/InstCombine/apint-shift.ll | 7 ++----- test/Transforms/InstCombine/pr17827.ll | 4 +--- test/Transforms/InstCombine/shift.ll | 6 ++---- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 230a1ff33d0..3d14e59ea0d 100644 --- a/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -469,8 +469,9 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, computeKnownBits(V, KnownZero, KnownOne, Depth, CxtI); break; } - case Instruction::Shl: - if (ConstantInt *SA = dyn_cast(I->getOperand(1))) { + case Instruction::Shl: { + const APInt *SA; + if (match(I->getOperand(1), m_APInt(SA))) { { Value *VarX; ConstantInt *C1; if (match(I->getOperand(0), m_Shr(m_Value(VarX), m_ConstantInt(C1)))) { @@ -503,6 +504,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, KnownZero.setLowBits(ShiftAmt); } break; + } case Instruction::LShr: { const APInt *SA; if (match(I->getOperand(1), m_APInt(SA))) { diff --git a/test/Transforms/InstCombine/apint-shift.ll b/test/Transforms/InstCombine/apint-shift.ll index f339de35d77..679a87a7efb 100644 --- a/test/Transforms/InstCombine/apint-shift.ll +++ b/test/Transforms/InstCombine/apint-shift.ll @@ -287,13 +287,10 @@ define i47 @test12(i47 %X) { ret i47 %sh2 } -; FIXME: Same as above with vectors. - define <2 x i47> @test12_splat_vec(<2 x i47> %X) { ; CHECK-LABEL: @test12_splat_vec( -; CHECK-NEXT: [[SH1:%.*]] = ashr <2 x i47> %X, -; CHECK-NEXT: [[SH2:%.*]] = shl nsw <2 x i47> [[SH1]], -; CHECK-NEXT: ret <2 x i47> [[SH2]] +; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i47> %X, +; CHECK-NEXT: ret <2 x i47> [[TMP1]] ; %sh1 = ashr <2 x i47> %X, %sh2 = shl <2 x i47> %sh1, diff --git a/test/Transforms/InstCombine/pr17827.ll b/test/Transforms/InstCombine/pr17827.ll index ada6edab69c..c9cbf764d7f 100644 --- a/test/Transforms/InstCombine/pr17827.ll +++ b/test/Transforms/InstCombine/pr17827.ll @@ -52,9 +52,7 @@ define i1 @test_shift_and_cmp_changed1(i8 %p, i8 %q) { define <2 x i1> @test_shift_and_cmp_changed1_vec(<2 x i8> %p, <2 x i8> %q) { ; CHECK-LABEL: @test_shift_and_cmp_changed1_vec( ; CHECK-NEXT: [[ANDP:%.*]] = and <2 x i8> %p, -; CHECK-NEXT: [[ANDQ:%.*]] = and <2 x i8> %q, -; CHECK-NEXT: [[OR:%.*]] = or <2 x i8> [[ANDQ]], [[ANDP]] -; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i8> [[OR]], +; CHECK-NEXT: [[SHL:%.*]] = shl nuw <2 x i8> [[ANDP]], ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[SHL]], ; CHECK-NEXT: ret <2 x i1> [[CMP]] ; diff --git a/test/Transforms/InstCombine/shift.ll b/test/Transforms/InstCombine/shift.ll index d5f489280a0..abcb8f17525 100644 --- a/test/Transforms/InstCombine/shift.ll +++ b/test/Transforms/InstCombine/shift.ll @@ -1049,12 +1049,11 @@ define i8 @test53_no_nuw(i8 %x) { } ; (X << C1) >>u C2 --> X << (C1 - C2) & (-1 >> C2) -; FIXME: Demanded bits should change the mask constant as it does for the scalar case. define <2 x i8> @test53_no_nuw_splat_vec(<2 x i8> %x) { ; CHECK-LABEL: @test53_no_nuw_splat_vec( ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i8> %x, -; CHECK-NEXT: [[B:%.*]] = and <2 x i8> [[TMP1]], +; CHECK-NEXT: [[B:%.*]] = and <2 x i8> [[TMP1]], ; CHECK-NEXT: ret <2 x i8> [[B]] ; %A = shl <2 x i8> %x, @@ -1257,8 +1256,7 @@ define i64 @test_64(i32 %t) { define <2 x i64> @test_64_splat_vec(<2 x i32> %t) { ; CHECK-LABEL: @test_64_splat_vec( -; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> %t, -; CHECK-NEXT: [[TMP1:%.*]] = shl nuw <2 x i32> [[AND]], +; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> %t, ; CHECK-NEXT: [[SHL:%.*]] = zext <2 x i32> [[TMP1]] to <2 x i64> ; CHECK-NEXT: ret <2 x i64> [[SHL]] ; -- 2.50.1