Index: lib/Analysis/ConstantFolding.cpp =================================================================== --- lib/Analysis/ConstantFolding.cpp +++ lib/Analysis/ConstantFolding.cpp @@ -1238,6 +1238,7 @@ /// Return true if it's even possible to fold a call to the specified function. bool llvm::canConstantFoldCallTo(const Function *F) { switch (F->getIntrinsicID()) { + case Intrinsic::expect: case Intrinsic::fabs: case Intrinsic::minnum: case Intrinsic::maxnum: @@ -1722,6 +1723,9 @@ if (Op2->isOne() && Op1->isZero()) // ctlz(0, 1) is undef. return UndefValue::get(Ty); return ConstantInt::get(Ty, Op1->getValue().countLeadingZeros()); + case Intrinsic::expect: + // llvm.expect(constant, ...) -> constant + return Op1; } } Index: test/Transforms/InstSimplify/call.ll =================================================================== --- test/Transforms/InstSimplify/call.ll +++ test/Transforms/InstSimplify/call.ll @@ -164,3 +164,14 @@ } declare noalias i8* @malloc(i64) + +; Constant fold llvm.expect(c, ...) -> c +define i64 @constant_fold_expect() { + %c = call i64 @llvm.expect.i64(i64 1, i64 0) + ret i64 %c + +; CHECK-LABEL: @constant_fold_expect +; CHECK: ret i64 1 +} + +declare i64 @llvm.expect.i64(i64, i64)