[llvm] 3291efc - [ValueTracking] Handle shufflevector constants in ComputeNumSignBits
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 23 17:48:05 PDT 2020
Author: Eli Friedman
Date: 2020-04-23T17:47:37-07:00
New Revision: 3291efc2b3bb7f438f9076f6c4484cadbbda899f
URL: https://github.com/llvm/llvm-project/commit/3291efc2b3bb7f438f9076f6c4484cadbbda899f
DIFF: https://github.com/llvm/llvm-project/commit/3291efc2b3bb7f438f9076f6c4484cadbbda899f.diff
LOG: [ValueTracking] Handle shufflevector constants in ComputeNumSignBits
Differential Revision: https://reviews.llvm.org/D78688
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/InstCombine/nsw.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index ddce360e3da6..056111bac4c7 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2906,7 +2906,11 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
case Instruction::ShuffleVector: {
// Collect the minimum number of sign bits that are shared by every vector
// element referenced by the shuffle.
- auto *Shuf = cast<ShuffleVectorInst>(U);
+ auto *Shuf = dyn_cast<ShuffleVectorInst>(U);
+ if (!Shuf) {
+ // FIXME: Add support for shufflevector constant expressions.
+ return 1;
+ }
APInt DemandedLHS, DemandedRHS;
// For undef elements, we don't know anything about the common state of
// the shuffle result.
diff --git a/llvm/test/Transforms/InstCombine/nsw.ll b/llvm/test/Transforms/InstCombine/nsw.ll
index c0b762f876f9..9746e9b583db 100644
--- a/llvm/test/Transforms/InstCombine/nsw.ll
+++ b/llvm/test/Transforms/InstCombine/nsw.ll
@@ -128,3 +128,15 @@ define <3 x i32> @shl_nuw_nsw_shuffle_undef_elt_splat_vec(<2 x i8> %x) {
ret <3 x i32> %t3
}
+; Make sure we don't crash on a ConstantExpr shufflevector
+define <vscale x 2 x i64> @mul_nuw_nsw_shuffle_constant_expr(<vscale x 2 x i8> %z) {
+; CHECK-LABEL: @mul_nuw_nsw_shuffle_constant_expr(
+; CHECK-NEXT: [[XX:%.*]] = zext <vscale x 2 x i8> [[Z:%.*]] to <vscale x 2 x i64>
+; CHECK-NEXT: [[T3:%.*]] = mul <vscale x 2 x i64> [[XX]], shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> undef, i64 3, i32 0), <vscale x 2 x i64> zeroinitializer, <vscale x 2 x i32> zeroinitializer)
+; CHECK-NEXT: ret <vscale x 2 x i64> [[T3]]
+;
+ %xx = zext <vscale x 2 x i8> %z to <vscale x 2 x i64>
+ %shuf = shufflevector <vscale x 2 x i64> insertelement (<vscale x 2 x i64> undef, i64 3, i32 0), <vscale x 2 x i64> zeroinitializer, <vscale x 2 x i32> zeroinitializer
+ %t3 = mul <vscale x 2 x i64> %shuf, %xx
+ ret <vscale x 2 x i64> %t3
+}
More information about the llvm-commits
mailing list