Index: lib/Analysis/ConstantFolding.cpp =================================================================== --- lib/Analysis/ConstantFolding.cpp +++ lib/Analysis/ConstantFolding.cpp @@ -1379,6 +1379,7 @@ case Intrinsic::fma: case Intrinsic::fmuladd: case Intrinsic::copysign: + case Intrinsic::invariant_group_barrier: case Intrinsic::round: case Intrinsic::masked_load: case Intrinsic::sadd_with_overflow: @@ -1769,7 +1770,14 @@ if (isa(Operands[0])) { if (IntrinsicID == Intrinsic::bswap || - IntrinsicID == Intrinsic::bitreverse) + IntrinsicID == Intrinsic::bitreverse || + IntrinsicID == Intrinsic::invariant_group_barrier) + return Operands[0]; + return nullptr; + } + + if (isa(Operands[0])) { + if (IntrinsicID == Intrinsic::invariant_group_barrier) return Operands[0]; return nullptr; } Index: test/Transforms/InstCombine/invariant.group.ll =================================================================== --- /dev/null +++ test/Transforms/InstCombine/invariant.group.ll @@ -0,0 +1,17 @@ +; RUN: opt -instcombine -S < %s | FileCheck %s + +; 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 i8* @llvm.invariant.group.barrier(i8*)