Index: lib/Transforms/IPO/MergeFunctions.cpp =================================================================== --- lib/Transforms/IPO/MergeFunctions.cpp +++ lib/Transforms/IPO/MergeFunctions.cpp @@ -464,6 +464,8 @@ if (C1->isNullValue() && C2->isNullValue() && isEquivalentType(C1->getType(), C2->getType())) return true; + if (const Function *F = dyn_cast(C2)) + if (F->isIntrinsic()) return false; // Try bitcasting C2 to C1's type. If the bitcast is legal and returns C1 // then they must have equal bit patterns. return C1->getType()->canLosslesslyBitCastTo(C2->getType()) && Index: test/Transforms/MergeFunc/intrinsics.ll =================================================================== --- /dev/null +++ test/Transforms/MergeFunc/intrinsics.ll @@ -0,0 +1,22 @@ +; RUN: opt -mergefunc -disable-output < %s +; This used to crash because mergefunc created a bitcast of an intrinsic. + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare i64 @llvm.bswap.i64(i64) unnamed_addr nounwind readnone +declare i8* @breaker(i8*) unnamed_addr + +; Function Attrs: inlinehint uwtable +define void @bswap_caller(i64) unnamed_addr { +entry-block: + call i64 @llvm.bswap.i64(i64 %0) + ret void +} + +; Function Attrs: inlinehint uwtable +define internal void @collider(i8*) unnamed_addr { +entry-block: + call i8* @breaker(i8* %0) + ret void +}