[PATCH] D95878: [AMDGPU]: Fixes an invalid clamp selection pattern.

Thomas Symalla via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 09:29:02 PST 2021


tsymalla created this revision.
tsymalla added a reviewer: arsenm.
Herald added subscribers: kerbowa, steven.zhang, pengfei, hiraditya, t-tye, tpr, dstuttard, yaxunl, nhaehnle, jvesely, kzhuravl.
tsymalla requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

When running the tests on PowerPC and x86, the lit test GlobalISel/trunc.ll fails at the memory sanitize step. This seems to be due to wrong invalid logic (which matches even if it shouldn't) and likely missing variable initialisation."


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95878

Files:
  llvm/lib/Target/AMDGPU/AMDGPUPreLegalizerCombiner.cpp


Index: llvm/lib/Target/AMDGPU/AMDGPUPreLegalizerCombiner.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPUPreLegalizerCombiner.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUPreLegalizerCombiner.cpp
@@ -41,8 +41,8 @@
       : B(B), MF(B.getMF()), MRI(*B.getMRI()), Helper(Helper){};
 
   struct ClampI64ToI16MatchInfo {
-    int64_t Cmp1;
-    int64_t Cmp2;
+    int64_t Cmp1 = 0;
+    int64_t Cmp2 = 0;
     Register Origin;
   };
 
@@ -71,18 +71,24 @@
   Register Base;
 
   // Try to match a combination of min / max MIR opcodes.
-  if (mi_match(MI.getOperand(1).getReg(), MRI, m_GSMin(m_Reg(Base), m_ICst(MatchInfo.Cmp1)))) {
-    if (!mi_match(Base, MRI, m_GSMax(m_Reg(MatchInfo.Origin), m_ICst(MatchInfo.Cmp2)))) {
-      return false;
-    }
+  bool continueMatch =
+      mi_match(MI.getOperand(1).getReg(), MRI,
+               m_GSMin(m_Reg(Base), m_ICst(MatchInfo.Cmp1))) &&
+      mi_match(Base, MRI,
+               m_GSMax(m_Reg(MatchInfo.Origin), m_ICst(MatchInfo.Cmp2)));
+
+  if (!continueMatch) {
+    continueMatch =
+        mi_match(MI.getOperand(1).getReg(), MRI,
+                 m_GSMax(m_Reg(Base), m_ICst(MatchInfo.Cmp1))) &&
+        mi_match(Base, MRI,
+                 m_GSMin(m_Reg(MatchInfo.Origin), m_ICst(MatchInfo.Cmp2)));
   }
 
-  if (mi_match(MI.getOperand(1).getReg(), MRI, m_GSMax(m_Reg(Base), m_ICst(MatchInfo.Cmp1)))) {
-    if (!mi_match(Base, MRI, m_GSMin(m_Reg(MatchInfo.Origin), m_ICst(MatchInfo.Cmp2)))) {
-      return false;
-    }
+  if (!continueMatch) {
+    return false;
   }
-   
+
   const auto Cmp1 = MatchInfo.Cmp1;
   const auto Cmp2 = MatchInfo.Cmp2;
   const auto Diff = std::abs(Cmp2 - Cmp1);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95878.320820.patch
Type: text/x-patch
Size: 1702 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210202/5c3c5e92/attachment.bin>


More information about the llvm-commits mailing list