diff options
author | Craig Topper <craig.topper@intel.com> | 2018-09-11 17:57:20 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@intel.com> | 2018-09-11 17:57:20 +0000 |
commit | 4e63db83873f22d185a3f27633aae710c2517efe (patch) | |
tree | 72314adc604f48ec1a0530d920c418e2e958b5b2 | |
parent | 5b7e21a6b7e35cd8fba49efe7462e610d78c9314 (diff) | |
download | bcm5719-llvm-4e63db83873f22d185a3f27633aae710c2517efe.tar.gz bcm5719-llvm-4e63db83873f22d185a3f27633aae710c2517efe.zip |
[InstCombine] Fix incorrect usage of getPrimitiveSizeInBits when we should be using the element size for vectors
For vectors, getPrimitiveSizeInBits returns the full vector width. This code should using the element size for vectors. This could be fixed by calling getScalarSizeInBits, but its even easier to just get it from the APInt we're checking.
Differential Revision: https://reviews.llvm.org/D51938
llvm-svn: 341971
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 3 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/mul.ll | 2 |
2 files changed, 2 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 6b11fe728fa..ee2136357ae 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -171,14 +171,13 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { if (match(&I, m_Mul(m_Value(NewOp), m_Constant(C1)))) { // Replace X*(2^C) with X << C, where C is either a scalar or a vector. if (Constant *NewCst = getLogBase2(NewOp->getType(), C1)) { - unsigned Width = NewCst->getType()->getPrimitiveSizeInBits(); BinaryOperator *Shl = BinaryOperator::CreateShl(NewOp, NewCst); if (I.hasNoUnsignedWrap()) Shl->setHasNoUnsignedWrap(); if (I.hasNoSignedWrap()) { const APInt *V; - if (match(NewCst, m_APInt(V)) && *V != Width - 1) + if (match(NewCst, m_APInt(V)) && *V != V->getBitWidth() - 1) Shl->setHasNoSignedWrap(); } diff --git a/llvm/test/Transforms/InstCombine/mul.ll b/llvm/test/Transforms/InstCombine/mul.ll index 788e55907a5..fc3773aa9f1 100644 --- a/llvm/test/Transforms/InstCombine/mul.ll +++ b/llvm/test/Transforms/InstCombine/mul.ll @@ -409,7 +409,7 @@ define i32 @test32(i32 %X) { define <2 x i32> @test32vec(<2 x i32> %X) { ; CHECK-LABEL: @test32vec( -; CHECK-NEXT: [[MUL:%.*]] = shl nsw <2 x i32> [[X:%.*]], <i32 31, i32 31> +; CHECK-NEXT: [[MUL:%.*]] = shl <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> |