Index: include/llvm/IR/PatternMatch.h =================================================================== --- include/llvm/IR/PatternMatch.h +++ include/llvm/IR/PatternMatch.h @@ -215,6 +215,7 @@ // Non-splat vector constant: check each element for a match. unsigned NumElts = V->getType()->getVectorNumElements(); assert(NumElts != 0 && "Constant vector with no elements?"); + bool HasNonUndefElements = false; for (unsigned i = 0; i != NumElts; ++i) { Constant *Elt = C->getAggregateElement(i); if (!Elt) @@ -224,8 +225,9 @@ auto *CI = dyn_cast(Elt); if (!CI || !this->isValue(CI->getValue())) return false; + HasNonUndefElements = true; } - return true; + return HasNonUndefElements; } } return false; @@ -272,6 +274,7 @@ // Non-splat vector constant: check each element for a match. unsigned NumElts = V->getType()->getVectorNumElements(); assert(NumElts != 0 && "Constant vector with no elements?"); + bool HasNonUndefElements = false; for (unsigned i = 0; i != NumElts; ++i) { Constant *Elt = C->getAggregateElement(i); if (!Elt) @@ -281,8 +284,9 @@ auto *CF = dyn_cast(Elt); if (!CF || !this->isValue(CF->getValueAPF())) return false; + HasNonUndefElements = true; } - return true; + return HasNonUndefElements; } } return false; Index: test/Transforms/InstSimplify/shr-scalar-vector-consistency.ll =================================================================== --- /dev/null +++ test/Transforms/InstSimplify/shr-scalar-vector-consistency.ll @@ -0,0 +1,24 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -instsimplify -S | FileCheck %s + +; This tests checks optimization consistency for scalar and vector code. +; If m_Zero() is able to match a vector undef, but not a scalar undef, +; the two cases will simplify differently. + +define i32 @test_scalar(i32 %a, i1 %b) { +; CHECK-LABEL: @test_scalar( +; CHECK-NEXT: ret i32 undef +; + %c = sext i1 %b to i32 + %d = ashr i32 undef, %c + ret i32 %d +} + +define <2 x i32> @test_vector(<2 x i32> %a, <2 x i1> %b) { +; CHECK-LABEL: @test_vector( +; CHECK-NEXT: ret <2 x i32> undef +; + %c = sext <2 x i1> %b to <2 x i32> + %d = ashr <2 x i32> undef, %c + ret <2 x i32> %d +} Index: test/Transforms/Reassociate/fp-expr.ll =================================================================== --- test/Transforms/Reassociate/fp-expr.ll +++ test/Transforms/Reassociate/fp-expr.ll @@ -4,8 +4,8 @@ define void @test1() { ; CHECK-LABEL: @test1( ; CHECK-NEXT: [[T1:%.*]] = tail call <4 x float> @blam() -; CHECK-NEXT: [[T23:%.*]] = fsub fast <4 x float> undef, [[T1]] -; CHECK-NEXT: [[T24:%.*]] = fadd fast <4 x float> [[T23]], undef +; CHECK-NEXT: [[T1_NEG:%.*]] = fsub fast <4 x float> , [[T1]] +; CHECK-NEXT: [[T24:%.*]] = fadd fast <4 x float> [[T1_NEG]], undef ; CHECK-NEXT: tail call void @wombat(<4 x float> [[T24]]) ; CHECK-NEXT: ret void ;