From c96f661d59cd81eec5e23b72db5a695765176f20 Mon Sep 17 00:00:00 2001 From: Jun Bum Lim Date: Fri, 27 Jan 2017 17:16:37 +0000 Subject: [PATCH] [CodeGenPrep]No negative cost in the ExtLd promotion Summary: This change prevent the signed value of cost from being negative as the value is passed as an unsigned argument. Reviewers: mcrosier, jmolloy, qcolombet, javed.absar Reviewed By: mcrosier, qcolombet Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D28871 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293307 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenPrepare.cpp | 5 ++++- .../AArch64/arm64-codegen-prepare-extload.ll | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CodeGenPrepare.cpp b/lib/CodeGen/CodeGenPrepare.cpp index bfcedaceb64..3029cb10a78 100644 --- a/lib/CodeGen/CodeGenPrepare.cpp +++ b/lib/CodeGen/CodeGenPrepare.cpp @@ -4297,7 +4297,10 @@ bool CodeGenPrepare::extLdPromotion(TypePromotionTransaction &TPT, // one extension but leave one. However, we optimistically keep going, // because the new extension may be removed too. long long TotalCreatedInstsCost = CreatedInstsCost + NewCreatedInstsCost; - TotalCreatedInstsCost -= ExtCost; + // FIXME: It would be possible to propagate a negative value instead of + // conservatively ceiling it to 0. + TotalCreatedInstsCost = + std::max((long long)0, (TotalCreatedInstsCost - ExtCost)); if (!StressExtLdPromotion && (TotalCreatedInstsCost > 1 || !isPromotedInstructionLegal(*TLI, *DL, PromotedVal))) { diff --git a/test/CodeGen/AArch64/arm64-codegen-prepare-extload.ll b/test/CodeGen/AArch64/arm64-codegen-prepare-extload.ll index c9f668f2c42..3d9c86139ed 100644 --- a/test/CodeGen/AArch64/arm64-codegen-prepare-extload.ll +++ b/test/CodeGen/AArch64/arm64-codegen-prepare-extload.ll @@ -636,3 +636,24 @@ define i64 @doNotPromoteBecauseOfPairedLoad(i32* %p, i32 %cst) { %final = add i64 %sextres, %zextLd0 ret i64 %final } + +define i64 @promoteZextShl(i1 %c, i16* %P) { +entry: +; OPTALL-LABEL: promoteZextShl +; OPTALL-LABEL: entry: +; OPT: %[[LD:.*]] = load i16, i16* %P +; OPT: %[[EXT:.*]] = zext i16 %[[LD]] to i64 +; OPT-LABEL: if.then: +; OPT: shl nsw i64 %[[EXT]], 1 +; DISABLE-LABEL: if.then: +; DISABLE: %r = sext i32 %shl2 to i64 + %ld = load i16, i16* %P + br i1 %c, label %end, label %if.then +if.then: + %z = zext i16 %ld to i32 + %shl2 = shl nsw i32 %z, 1 + %r = sext i32 %shl2 to i64 + ret i64 %r +end: + ret i64 0 +} -- 2.40.0