[PATCH] D91512: [AArch64][Isel] Avoid implicit zext for SIGN_EXTEND_INREG (TRUNCATE)

guopeilin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 27 06:30:04 PDT 2021


guopeilin updated this revision to Diff 369087.
guopeilin edited the summary of this revision.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91512/new/

https://reviews.llvm.org/D91512

Files:
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/test/CodeGen/AArch64/aarch64-avoid-implicit-zext-for-sign_extend_inreg.ll


Index: llvm/test/CodeGen/AArch64/aarch64-avoid-implicit-zext-for-sign_extend_inreg.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/aarch64-avoid-implicit-zext-for-sign_extend_inreg.ll
@@ -0,0 +1,17 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -O3 -mtriple=aarch64-unknown-linux-gnu < %s | FileCheck %s
+
+define i64 @test(i64 %0) {
+; CHECK-LABEL: test:
+; CHECK:       // %bb.0: // %entry
+; CHECK-NEXT:    sbfx x8, x0, #30, #16
+; CHECK-NEXT:    mov w0, w8
+; CHECK-NEXT:    ret
+entry:
+  %1 = lshr i64 %0, 30
+  %2 = shl nuw nsw i64 %1, 16
+  %3 = trunc i64 %2 to i32
+  %4 = ashr exact i32 %3, 16
+  %5 = zext i32 %4 to i64
+  ret i64 %5
+}
Index: llvm/lib/Target/AArch64/AArch64ISelLowering.h
===================================================================
--- llvm/lib/Target/AArch64/AArch64ISelLowering.h
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.h
@@ -455,6 +455,16 @@
 // 32 bits, they're probably just qualifying a CopyFromReg.
 static inline bool isDef32(const SDNode &N) {
   unsigned Opc = N.getOpcode();
+
+  // For some cases, isBitfieldExtractOpFromSExtInReg() will try to use
+  // SBFMXri + EXTRACT_SUBREG to implement sign_extend_inreg(truncate)
+  // during ISel, However COPY is likely to be erased after register coalescing,
+  // So if we want to zext this value, we should not use implicit way.
+  if (Opc == ISD::SIGN_EXTEND_INREG) {
+    SDValue Opr = N.getOperand(0);
+    return Opr->getOpcode() != ISD::TRUNCATE;
+  }
+
   return Opc != ISD::TRUNCATE && Opc != TargetOpcode::EXTRACT_SUBREG &&
          Opc != ISD::CopyFromReg && Opc != ISD::AssertSext &&
          Opc != ISD::AssertZext && Opc != ISD::AssertAlign &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91512.369087.patch
Type: text/x-patch
Size: 1775 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210827/bcb52709/attachment.bin>


More information about the llvm-commits mailing list