Index: llvm/lib/Transforms/IPO/FunctionSpecialization.cpp =================================================================== --- llvm/lib/Transforms/IPO/FunctionSpecialization.cpp +++ llvm/lib/Transforms/IPO/FunctionSpecialization.cpp @@ -677,8 +677,12 @@ auto *V = CS.getArgOperand(A->getArgNo()); if (isa(V)) return false; - if (isa(V)) - return false; + + // For now, constant expressions are fine but only if they are function + // calls. + if (auto *CE = dyn_cast(V)) + if (!isa(CE->getOperand(0))) + return false; // TrackValueOfGlobalVariable only tracks scalar global variables. if (auto *GV = dyn_cast(V)) { Index: llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression3.ll =================================================================== --- llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression3.ll +++ llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression3.ll @@ -4,8 +4,8 @@ define i32 @main() { ; CHECK-LABEL: @main( ; CHECK-NEXT: bb: -; CHECK-NEXT: tail call void @wombat(i8* undef, i64 undef, i64 undef, i32 (i8*, i8*)* bitcast (i32 ()* @quux to i32 (i8*, i8*)*)) -; CHECK-NEXT: tail call void @wombat(i8* undef, i64 undef, i64 undef, i32 (i8*, i8*)* bitcast (i32 ()* @eggs to i32 (i8*, i8*)*)) +; CHECK-NEXT: tail call void @wombat.1(i8* undef, i64 undef, i64 undef, i32 (i8*, i8*)* bitcast (i32 ()* @quux to i32 (i8*, i8*)*)) +; CHECK-NEXT: tail call void @wombat.2(i8* undef, i64 undef, i64 undef, i32 (i8*, i8*)* bitcast (i32 ()* @eggs to i32 (i8*, i8*)*)) ; CHECK-NEXT: ret i32 undef ; bb: