Index: lib/Analysis/InstructionSimplify.cpp =================================================================== --- lib/Analysis/InstructionSimplify.cpp +++ lib/Analysis/InstructionSimplify.cpp @@ -4429,6 +4429,13 @@ return *ArgBegin; return nullptr; } + case Intrinsic::invariant_group_barrier: { + // invariant.group.barrier(null) -> null + // invariant.group.barrier(undef) -> undef + if (isa(*ArgBegin) || isa(*ArgBegin)) + return *ArgBegin; + return nullptr; + } default: return nullptr; } Index: test/Transforms/GVN/invariant.group.ll =================================================================== --- test/Transforms/GVN/invariant.group.ll +++ test/Transforms/GVN/invariant.group.ll @@ -486,6 +486,20 @@ ret void } +; CHECK-LABEL: define i8* @siplifyNullBarrier() +define i8* @siplifyNullBarrier() { +; CHECK-NEXT: ret i8* null + %b2 = call i8* @llvm.invariant.group.barrier(i8* null) + ret i8* %b2 +} + +; CHECK-LABEL: define i8* @siplifyUndefBarrier() +define i8* @siplifyUndefBarrier() { +; CHECK-NEXT: ret i8* undef + %b2 = call i8* @llvm.invariant.group.barrier(i8* undef) + ret i8* %b2 +} + declare void @foo(i8*) declare void @foo2(i8*, i8)