Index: lib/Transforms/InstCombine/InstCombineCalls.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCalls.cpp +++ lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2168,6 +2168,35 @@ break; } + case Intrinsic::x86_pclmulqdq: { + if (auto *C = dyn_cast(II->getArgOperand(2))) { + unsigned Imm = C->getZExtValue(); + + bool MadeChange = false; + Value *Arg0 = II->getArgOperand(0); + Value *Arg1 = II->getArgOperand(1); + unsigned VWidth = Arg0->getType()->getVectorNumElements(); + APInt UndefElts(VWidth, 0); + APInt DemandedElts(VWidth, 0); + + DemandedElts = (Imm & 0x01) ? 2 : 1; + if (Value *V = SimplifyDemandedVectorElts(Arg0, DemandedElts, + UndefElts)) { + II->setArgOperand(0, V); + MadeChange = true; + } + DemandedElts = (Imm & 0x10) ? 2 : 1; + if (Value *V = SimplifyDemandedVectorElts(Arg1, DemandedElts, + UndefElts)) { + II->setArgOperand(1, V); + MadeChange = true; + } + if (MadeChange) + return II; + } + break; + } + case Intrinsic::x86_sse41_insertps: if (Value *V = simplifyX86insertps(*II, *Builder)) return replaceInstUsesWith(*II, V); Index: test/Transforms/InstCombine/x86-clmulqdq.ll =================================================================== --- /dev/null +++ test/Transforms/InstCombine/x86-clmulqdq.ll @@ -0,0 +1,48 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -instcombine -S | FileCheck %s + +declare <2 x i64> @llvm.x86.pclmulqdq(<2 x i64>, <2 x i64>, i8) + +define <2 x i64> @test_demanded_elts_pclmulqdq_0(<2 x i64> %a0, <2 x i64> %a1) { +; CHECK-LABEL: @test_demanded_elts_pclmulqdq_0( +; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i64> @llvm.x86.pclmulqdq(<2 x i64> [[A0:%.*]], <2 x i64> [[A1:%.*]], i8 0) +; CHECK-NEXT: ret <2 x i64> [[TMP1]] +; + %1 = insertelement <2 x i64> %a0, i64 1, i64 1 + %2 = insertelement <2 x i64> %a1, i64 1, i64 1 + %3 = call <2 x i64> @llvm.x86.pclmulqdq(<2 x i64> %1, <2 x i64> %2, i8 0) + ret <2 x i64> %3 +} + +define <2 x i64> @test_demanded_elts_pclmulqdq_1(<2 x i64> %a0, <2 x i64> %a1) { +; CHECK-LABEL: @test_demanded_elts_pclmulqdq_1( +; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i64> @llvm.x86.pclmulqdq(<2 x i64> , <2 x i64> [[A1:%.*]], i8 1) +; CHECK-NEXT: ret <2 x i64> [[TMP1]] +; + %1 = insertelement <2 x i64> %a0, i64 1, i64 1 + %2 = insertelement <2 x i64> %a1, i64 1, i64 1 + %3 = call <2 x i64> @llvm.x86.pclmulqdq(<2 x i64> %1, <2 x i64> %2, i8 1) + ret <2 x i64> %3 +} + +define <2 x i64> @test_demanded_elts_pclmulqdq_16(<2 x i64> %a0, <2 x i64> %a1) { +; CHECK-LABEL: @test_demanded_elts_pclmulqdq_16( +; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i64> @llvm.x86.pclmulqdq(<2 x i64> [[A0:%.*]], <2 x i64> , i8 16) +; CHECK-NEXT: ret <2 x i64> [[TMP1]] +; + %1 = insertelement <2 x i64> %a0, i64 1, i64 1 + %2 = insertelement <2 x i64> %a1, i64 1, i64 1 + %3 = call <2 x i64> @llvm.x86.pclmulqdq(<2 x i64> %1, <2 x i64> %2, i8 16) + ret <2 x i64> %3 +} + +define <2 x i64> @test_demanded_elts_pclmulqdq_17(<2 x i64> %a0, <2 x i64> %a1) { +; CHECK-LABEL: @test_demanded_elts_pclmulqdq_17( +; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i64> @llvm.x86.pclmulqdq(<2 x i64> , <2 x i64> , i8 17) +; CHECK-NEXT: ret <2 x i64> [[TMP1]] +; + %1 = insertelement <2 x i64> %a0, i64 1, i64 1 + %2 = insertelement <2 x i64> %a1, i64 1, i64 1 + %3 = call <2 x i64> @llvm.x86.pclmulqdq(<2 x i64> %1, <2 x i64> %2, i8 17) + ret <2 x i64> %3 +}