Index: lib/Transforms/Scalar/InstSimplifyPass.cpp =================================================================== --- lib/Transforms/Scalar/InstSimplifyPass.cpp +++ lib/Transforms/Scalar/InstSimplifyPass.cpp @@ -17,6 +17,7 @@ #include "llvm/IR/DataLayout.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/Function.h" +#include "llvm/IR/PatternMatch.h" #include "llvm/IR/Type.h" #include "llvm/Pass.h" #include "llvm/Transforms/Utils.h" @@ -46,6 +47,15 @@ // Don't waste time simplifying unused instructions. if (!I->use_empty()) { + using namespace PatternMatch; + if (match(I, m_Intrinsic())) { + Constant *RetVal = ConstantInt::get(I->getType(), 0); + replaceAndRecursivelySimplify(I, RetVal, nullptr, nullptr); + BI = BB->begin(); + BE = BB->end(); + Changed = true; + continue; + } if (Value *V = SimplifyInstruction(I, SQ, ORE)) { // Mark all uses for resimplification next time round the loop. for (User *U : I->users()) Index: test/CodeGen/Generic/is-constant.ll =================================================================== --- test/CodeGen/Generic/is-constant.ll +++ test/CodeGen/Generic/is-constant.ll @@ -1,7 +1,12 @@ -; RUN: opt -O2 -S < %s | FileCheck %s +; RUN: opt --early-cse --inline --simplifycfg -S < %s | FileCheck %s ; RUN: llc -o /dev/null 2>&1 < %s ; RUN: llc -O0 -o /dev/null 2>&1 < %s +;; Ensure that the Simplify Instructions pass removes all remaining +;; llvm.is.constant intrinsics. +; RUN: opt --early-cse --inline --instsimplify --simplifycfg -S < %s | FileCheck --check-prefix=O2 %s +; O2-NOT: call i1 @llvm.is.constant + ;; The llc runs above are just to ensure it doesn't blow up upon ;; seeing an is_constant intrinsic.