[PATCH] D66991: [PowerPC] Fix SH field overflow issue

Yi-Hong Lyu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 31 20:37:05 PDT 2019


Yi-Hong.Lyu updated this revision to Diff 218252.
Yi-Hong.Lyu added a comment.

Address Stefan's comments


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

https://reviews.llvm.org/D66991

Files:
  llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
  llvm/test/CodeGen/PowerPC/convert-rr-to-ri-instrs.ll


Index: llvm/test/CodeGen/PowerPC/convert-rr-to-ri-instrs.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/convert-rr-to-ri-instrs.ll
@@ -0,0 +1,73 @@
+; RUN: llc -mcpu=pwr9 -O3 -verify-machineinstrs -ppc-asm-full-reg-names < %s | FileCheck %s
+target datalayout = "e-m:e-i64:64-n32:64"
+target triple = "powerpc64le-unknown-linux-gnu"
+
+; PowerPC Pre-Emit Peephole converts
+;   renamable $r4 = LI 0
+;   renamable $r5 = SRW renamable $r3, renamable $r4
+; to
+;   renamable $r4 = LI 0
+;   renamable $r5 = RLWINM renamable $r3, 32, 0, 31
+; so the assertion fails in assembly printing stage. The fix convert it to
+;   renamable $r4 = LI 0
+;   renamable $r5 = RLWINM renamable $r3, 0, 0, 31
+; instead.
+; We don't use MIR tests because llc doesn't serialize IsSSA property properly
+; so it doesn't do the conversion
+define void @special_right_shift32_0() {
+; CHECK-LABEL: special_right_shift32_0:
+; CHECK:         slwi r[[#]], r[[#]], 0
+bb:
+  %tmp = load i32, i32* undef, align 4
+  br label %bb1
+
+bb1:                                              ; preds = %bb8, %bb
+  %tmp2 = phi i32 [ undef, %bb8 ], [ %tmp, %bb ]
+  %tmp3 = phi i32 [ %tmp9, %bb8 ], [ 0, %bb ]
+  %tmp4 = shl i32 1, %tmp3
+  %tmp5 = and i32 %tmp2, %tmp4
+  %tmp6 = icmp eq i32 %tmp5, 0
+  br i1 %tmp6, label %bb8, label %bb7
+
+bb7:                                              ; preds = %bb1
+  unreachable
+
+bb8:                                              ; preds = %bb1
+  %tmp9 = add nuw nsw i32 %tmp3, 1
+  br label %bb1
+}
+
+; PowerPC Pre-Emit Peephole converts
+;   renamable $x4 = LI8 0
+;   renamable $x5 = SRD renamable $x3, renamable $r4
+; to
+;   renamable $x4 = LI8 0
+;   renamable $x5 = RLDICL renamable $x3, 64, 0
+; so the assertion fails in assembly printing stage. The fix convert it to
+;   renamable $x4 = LI8 0
+;   renamable $x5 = RLDICL renamable $x3, 0, 0
+; instead.
+; We don't use MIR tests because llc doesn't serialize IsSSA property properly
+; so it doesn't do the conversion
+define void @special_right_shift64_0() {
+; CHECK-LABEL: special_right_shift64_0:
+; CHECK:         rotldi r[[#]], r[[#]], 0
+bb:
+  %tmp = load i64, i64* undef, align 4
+  br label %bb1
+
+bb1:                                              ; preds = %bb8, %bb
+  %tmp2 = phi i64 [ undef, %bb8 ], [ %tmp, %bb ]
+  %tmp3 = phi i64 [ %tmp9, %bb8 ], [ 0, %bb ]
+  %tmp4 = shl i64 1, %tmp3
+  %tmp5 = and i64 %tmp2, %tmp4
+  %tmp6 = icmp eq i64 %tmp5, 0
+  br i1 %tmp6, label %bb8, label %bb7
+
+bb7:                                              ; preds = %bb1
+  unreachable
+
+bb8:                                              ; preds = %bb1
+  %tmp9 = add nuw nsw i64 %tmp3, 1
+  br label %bb1
+}
Index: llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
+++ llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
@@ -3582,7 +3582,7 @@
         // The 32 bit and 64 bit instructions are quite different.
         if (SpecialShift32) {
           // Left shifts use (N, 0, 31-N), right shifts use (32-N, N, 31).
-          uint64_t SH = RightShift ? 32 - ShAmt : ShAmt;
+          uint64_t SH = ShAmt == 0 ? 0 : RightShift ? 32 - ShAmt : ShAmt;
           uint64_t MB = RightShift ? ShAmt : 0;
           uint64_t ME = RightShift ? 31 : 31 - ShAmt;
           replaceInstrOperandWithImm(MI, III.OpNoForForwarding, SH);
@@ -3590,7 +3590,7 @@
             .addImm(ME);
         } else {
           // Left shifts use (N, 63-N), right shifts use (64-N, N).
-          uint64_t SH = RightShift ? 64 - ShAmt : ShAmt;
+          uint64_t SH = ShAmt == 0 ? 0 : RightShift ? 64 - ShAmt : ShAmt;
           uint64_t ME = RightShift ? ShAmt : 63 - ShAmt;
           replaceInstrOperandWithImm(MI, III.OpNoForForwarding, SH);
           MachineInstrBuilder(*MI.getParent()->getParent(), MI).addImm(ME);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66991.218252.patch
Type: text/x-patch
Size: 3941 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190901/8b519670/attachment.bin>


More information about the llvm-commits mailing list