Index: lib/CodeGen/CodeGenPrepare.cpp =================================================================== --- lib/CodeGen/CodeGenPrepare.cpp +++ lib/CodeGen/CodeGenPrepare.cpp @@ -2956,7 +2956,7 @@ // get through it and this method should not be called. Instruction *ExtOpnd = cast(Ext->getOperand(0)); CreatedInstsCost = 0; - if (!ExtOpnd->hasOneUse()) { + if (!ExtOpnd->hasOneUse() || ExtOpnd->isUsedByMetadata()) { // ExtOpnd will be promoted. // All its uses, but Ext, will need to use a truncated value of the // promoted version. Index: test/CodeGen/X86/metadata-trunc.ll =================================================================== --- /dev/null +++ test/CodeGen/X86/metadata-trunc.ll @@ -0,0 +1,34 @@ +; RUN: opt -codegenprepare %s -S | FileCheck %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) +define void @isLegalUTF8Sequence() { +entry: + %0 = load i8, i8* undef, align 1, !tbaa !9 + %conv = sext i8 %0 to i32 + %add = add nsw i32 %conv, 1, !dbg !16 +; CHECK-NOT: tail call void @llvm.dbg.value(metadata i64 +; CHECK: tail call void @llvm.dbg.value(metadata i32 + tail call void @llvm.dbg.value(metadata i32 %add, i64 0, metadata !13, metadata !15), !dbg !16 + %conv1 = sext i32 %add to i64 + ret void +} + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!8} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (https://github.com/llvm-mirror/clang 89dda3855cda574f355e6defa1d77bdae5053994) (llvm/trunk 257826)", isOptimized: true, runtimeVersion: 0, emissionKind: 1, subprograms: !5) +!1 = !DIFile(filename: "none", directory: ".") +!5 = !{!6} +!6 = distinct !DISubprogram(name: "isLegalUTF8Sequence", scope: !1, file: !1, line: 386, type: !7, isLocal: false, isDefinition: true, scopeLine: 386, flags: DIFlagPrototyped, isOptimized: true) +!7 = distinct !DISubroutineType(types: null) +!8 = !{i32 2, !"Debug Info Version", i32 3} +!9 = !{!10, !10, i64 0} +!10 = !{!"omnipotent char", !11, i64 0} +!11 = !{!"Simple C/C++ TBAA"} +!13 = !DILocalVariable(name: "length", scope: !6, file: !1, line: 387, type: !14) +!14 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!15 = !DIExpression() +!16 = !DILocation(line: 387, column: 9, scope: !6)