Index: llvm/trunk/lib/Target/Hexagon/HexagonVectorLoopCarriedReuse.cpp =================================================================== --- llvm/trunk/lib/Target/Hexagon/HexagonVectorLoopCarriedReuse.cpp +++ llvm/trunk/lib/Target/Hexagon/HexagonVectorLoopCarriedReuse.cpp @@ -429,11 +429,18 @@ for (int OpNo = 0; OpNo < NumOperands; ++OpNo) { Value *Op = I->getOperand(OpNo); + Value *BEOp = BEUser->getOperand(OpNo); + Instruction *OpInst = dyn_cast(Op); - if (!OpInst) - continue; + if (!OpInst) { + if (Op == BEOp) + continue; + // Do not allow reuse to occur when the operands may be different + // values. + BEUser = nullptr; + break; + } - Value *BEOp = BEUser->getOperand(OpNo); Instruction *BEOpInst = dyn_cast(BEOp); if (!isDepChainBtwn(OpInst, BEOpInst, Iters)) { Index: llvm/trunk/test/CodeGen/Hexagon/hexagon_vector_loop_carried_reuse_invalid.ll =================================================================== --- llvm/trunk/test/CodeGen/Hexagon/hexagon_vector_loop_carried_reuse_invalid.ll +++ llvm/trunk/test/CodeGen/Hexagon/hexagon_vector_loop_carried_reuse_invalid.ll @@ -0,0 +1,27 @@ +; RUN: opt -hexagon-vlcr < %s -S | FileCheck %s + +; Test that reuse doesn't occur due to two shufflevectors with different masks. + +; CHECK-NOT: extract.h.hexagon.vlcr + +define dso_local void @test() local_unnamed_addr #0 { +entry: + %0 = tail call <64 x i32> @llvm.hexagon.V6.vunpackuh.128B(<32 x i32> undef) + br i1 undef, label %for.end, label %for.body + +for.body: + %a = phi <64 x i32> [ %1, %for.body ], [ %0, %entry ] + %extract.h = shufflevector <64 x i32> %a, <64 x i32> undef, <32 x i32> + %1 = tail call <64 x i32> @llvm.hexagon.V6.vaddw.dv.128B(<64 x i32> undef, <64 x i32> undef) + %extract.l = shufflevector <64 x i32> %1, <64 x i32> undef, <32 x i32> + br label %for.body + +for.end: + ret void +} + +declare <64 x i32> @llvm.hexagon.V6.vunpackuh.128B(<32 x i32>) #1 +declare <64 x i32> @llvm.hexagon.V6.vaddw.dv.128B(<64 x i32>, <64 x i32>) #1 + +attributes #0 = { "use-soft-float"="false" } +attributes #1 = { nounwind readnone }