Index: lib/CodeGen/CodeGenPrepare.cpp =================================================================== --- lib/CodeGen/CodeGenPrepare.cpp +++ lib/CodeGen/CodeGenPrepare.cpp @@ -187,6 +187,7 @@ unsigned CreatedInstCost); bool splitBranchCondition(Function &F); bool simplifyOffsetableRelocate(Instruction &I); + void stripInvariantGroupMetadata(Instruction &I); }; } @@ -4425,6 +4426,7 @@ return OptimizeCmpExpression(CI); if (LoadInst *LI = dyn_cast(I)) { + stripInvariantGroupMetadata(*LI); if (TLI) { unsigned AS = LI->getPointerAddressSpace(); return OptimizeMemoryInst(I, I->getOperand(0), LI->getType(), AS); @@ -4433,6 +4435,7 @@ } if (StoreInst *SI = dyn_cast(I)) { + stripInvariantGroupMetadata(*SI); if (TLI) { unsigned AS = SI->getPointerAddressSpace(); return OptimizeMemoryInst(I, SI->getOperand(1), @@ -4831,3 +4834,8 @@ } return MadeChange; } + +void CodeGenPrepare::stripInvariantGroupMetadata(Instruction &I) { + if (auto *InvariantMD = I.getMetadata("invariant.group")) + I.dropUnknownNonDebugMetadata(InvariantMD->getMetadataID()); +} Index: test/Transforms/CodeGenPrepare/invariant.group.ll =================================================================== --- /dev/null +++ test/Transforms/CodeGenPrepare/invariant.group.ll @@ -0,0 +1,23 @@ +; RUN: opt -codegenprepare -S < %s | FileCheck %s + +@tmp = global i8 0 + +; CHECK-LABEL: define void @foo() { +define void @foo() { +enter: + ; CHECK-NOT: !invariant.group + ; CHECK-NOT: @llvm.invariant.group.barrier( + ; CHECK: %val = load i8, i8* @tmp + %val = load i8, i8* @tmp, !invariant.group !0 + %ptr = call i8* @llvm.invariant.group.barrier(i8* @tmp) + + ; CHECK: store i8 42, i8* @tmp + store i8 42, i8* %ptr, !invariant.group !0 + + ret void +} +; CHECK-LABEL: } + +declare i8* @llvm.invariant.group.barrier(i8*) + +!0 = !{!"something"} \ No newline at end of file