[llvm] r293307 - [CodeGenPrep]No negative cost in the ExtLd promotion

Jun Bum Lim via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 27 09:16:37 PST 2017


Author: junbuml
Date: Fri Jan 27 11:16:37 2017
New Revision: 293307

URL: http://llvm.org/viewvc/llvm-project?rev=293307&view=rev
Log:
[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

Modified:
    llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
    llvm/trunk/test/CodeGen/AArch64/arm64-codegen-prepare-extload.ll

Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=293307&r1=293306&r2=293307&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Fri Jan 27 11:16:37 2017
@@ -4297,7 +4297,10 @@ bool CodeGenPrepare::extLdPromotion(Type
     // 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))) {

Modified: llvm/trunk/test/CodeGen/AArch64/arm64-codegen-prepare-extload.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/arm64-codegen-prepare-extload.ll?rev=293307&r1=293306&r2=293307&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/arm64-codegen-prepare-extload.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/arm64-codegen-prepare-extload.ll Fri Jan 27 11:16:37 2017
@@ -636,3 +636,24 @@ define i64 @doNotPromoteBecauseOfPairedL
   %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
+}




More information about the llvm-commits mailing list