[llvm] r258851 - WebAssembly: don't optimize memcpy/memmove/memcpy to frame index

JF Bastien via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 26 12:22:42 PST 2016


Author: jfb
Date: Tue Jan 26 14:22:42 2016
New Revision: 258851

URL: http://llvm.org/viewvc/llvm-project?rev=258851&view=rev
Log:
WebAssembly: don't optimize memcpy/memmove/memcpy to frame index

r258781 optimized memcpy/memmove/memcpy so the intrinsic call can return its first argument, but missed the frame index case. Teach it to ignore that case so C code doesn't assert out in these cases.

Modified:
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp
    llvm/trunk/test/CodeGen/WebAssembly/mem-intrinsics.ll

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp?rev=258851&r1=258850&r2=258851&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyPeephole.cpp Tue Jan 26 14:22:42 2016
@@ -113,16 +113,21 @@ bool WebAssemblyPeephole::runOnMachineFu
               Name == TLI.getLibcallName(RTLIB::MEMSET)) {
             LibFunc::Func Func;
             if (LibInfo.getLibFunc(Name, Func)) {
-              if (!MI.getOperand(2).isReg())
-                report_fatal_error(
-                    "Call to builtin function with wrong signature");
-              MachineOperand &MO = MI.getOperand(0);
-              unsigned OldReg = MO.getReg();
-              unsigned NewReg = MI.getOperand(2).getReg();
-              if (MRI.getRegClass(NewReg) != MRI.getRegClass(OldReg))
-                report_fatal_error(
-                    "Call to builtin function with wrong signature");
-              Changed |= MaybeRewriteToDiscard(OldReg, NewReg, MO, MFI, MRI);
+              const auto &Op2 = MI.getOperand(2);
+              if (Op2.isReg()) {
+                MachineOperand &MO = MI.getOperand(0);
+                unsigned OldReg = MO.getReg();
+                unsigned NewReg = Op2.getReg();
+                if (MRI.getRegClass(NewReg) != MRI.getRegClass(OldReg))
+                  report_fatal_error("Peephole: call to builtin function with "
+                                     "wrong signature, from/to mismatch");
+                Changed |= MaybeRewriteToDiscard(OldReg, NewReg, MO, MFI, MRI);
+              } else if (Op2.isFI()) {
+                break;
+              } else {
+                report_fatal_error("Peephole: call to builtin function with "
+                                   "wrong signature, not consuming reg");
+              }
             }
           }
         }

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp?rev=258851&r1=258850&r2=258851&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyStoreResults.cpp Tue Jan 26 14:22:42 2016
@@ -150,16 +150,22 @@ bool WebAssemblyStoreResults::runOnMachi
               Name == TLI.getLibcallName(RTLIB::MEMSET)) {
             LibFunc::Func Func;
             if (LibInfo.getLibFunc(Name, Func)) {
-              if (!MI.getOperand(2).isReg())
-                report_fatal_error(
-                    "Call to builtin function with wrong signature");
-              unsigned FromReg = MI.getOperand(2).getReg();
-              unsigned ToReg = MI.getOperand(0).getReg();
-              if (MRI.getRegClass(FromReg) != MRI.getRegClass(ToReg))
-                report_fatal_error(
-                    "Call to builtin function with wrong signature");
-              Changed |=
-                  ReplaceDominatedUses(MBB, MI, FromReg, ToReg, MRI, MDT);
+              const auto &Op2 = MI.getOperand(2);
+              if (Op2.isReg()) {
+                unsigned FromReg = Op2.getReg();
+                unsigned ToReg = MI.getOperand(0).getReg();
+                if (MRI.getRegClass(FromReg) != MRI.getRegClass(ToReg))
+                  report_fatal_error("Store results: call to builtin function "
+                                     "with wrong signature, from/to mismatch");
+                Changed |=
+                    ReplaceDominatedUses(MBB, MI, FromReg, ToReg, MRI, MDT);
+              } else if (Op2.isFI()) {
+                break;
+              } else {
+                report_fatal_error("Store results: call to builtin function "
+                                   "with wrong signature, not consuming reg or "
+                                   "frame index");
+              }
             }
           }
         }

Modified: llvm/trunk/test/CodeGen/WebAssembly/mem-intrinsics.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/mem-intrinsics.ll?rev=258851&r1=258850&r2=258851&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/mem-intrinsics.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/mem-intrinsics.ll Tue Jan 26 14:22:42 2016
@@ -58,3 +58,14 @@ define void @set_no(i8* %dst, i8 %src, i
   call void @llvm.memset.p0i8.i32(i8* %dst, i8 %src, i32 %len, i32 1, i1 false)
   ret void
 }
+
+; CHECK-LABEL: frame_index:
+; CHECK: i32.call $discard=, memset at FUNCTION, $3, $pop1, $pop0{{$}}
+; CHECK: return{{$}}
+define void @frame_index() {
+entry:
+  %a = alloca [2048 x i8], align 16
+  %0 = getelementptr inbounds [2048 x i8], [2048 x i8]* %a, i32 0, i32 0
+  call void @llvm.memset.p0i8.i32(i8* %0, i8 256, i32 1024, i32 16, i1 false)
+  ret void
+}




More information about the llvm-commits mailing list