Index: lib/CodeGen/CodeGenPrepare.cpp =================================================================== --- lib/CodeGen/CodeGenPrepare.cpp +++ lib/CodeGen/CodeGenPrepare.cpp @@ -1853,6 +1853,17 @@ if (II) { switch (II->getIntrinsicID()) { default: break; + case Intrinsic::sideeffect: { + II->eraseFromParent(); + return true; + } + case Intrinsic::assume: + case Intrinsic::var_annotation: { + Value *Arg = II->getOperand(0); + II->eraseFromParent(); + RecursivelyDeleteTriviallyDeadInstructions(Arg); + return true; + } case Intrinsic::experimental_widenable_condition: { // Give up on future widening oppurtunties so that we can fold away dead // paths and merge blocks before going into block-local instruction Index: test/Transforms/CodeGenPrepare/drop-intrinsics.ll =================================================================== --- test/Transforms/CodeGenPrepare/drop-intrinsics.ll +++ test/Transforms/CodeGenPrepare/drop-intrinsics.ll @@ -0,0 +1,37 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -codegenprepare -S %s | FileCheck %s + +declare i32 @foo() +declare i8* @bar() +declare void @llvm.assume(i1) +declare void @llvm.sideeffect() +declare void @llvm.var.annotation(i8*, i8*, i8*, i32) + +define void @drop_llvm_assume() { +; CHECK-LABEL: @drop_llvm_assume( +; CHECK-NEXT: ret void +; + %call = tail call i32 @foo() #0 + %cmp = icmp eq i32 %call, 1 + call void @llvm.assume(i1 %cmp) + ret void +} + +define void @drop_llvm_sideeffect() { +; CHECK-LABEL: @drop_llvm_sideeffect( +; CHECK-NEXT: ret void +; + call void @llvm.sideeffect() + ret void +} + +define void @drop_llvm_var_annotation() { +; CHECK-LABEL: @drop_llvm_var_annotation( +; CHECK-NEXT: ret void +; + %s = call i8* @bar() #0 + call void @llvm.var.annotation(i8* %s, i8* null, i8* null, i32 0) + ret void +} + +attributes #0 = { nounwind readnone }