[PATCH] D97099: [ValueTracking] Infer context for arguments

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 19 16:25:03 PST 2021


reames created this revision.
reames added reviewers: nikic, jdoerfert, gilr.
Herald added subscribers: dantrushin, hiraditya, mcrosier.
Herald added a reviewer: bollu.
reames requested review of this revision.
Herald added a project: LLVM.

This is yet another alternative patch in the D93974 <https://reviews.llvm.org/D93974>,  D97077 <https://reviews.llvm.org/D97077>. and D97092 <https://reviews.llvm.org/D97092> family.

The notion of this patch is that we can set the context for the argument the same way we do for instructions.  This doesn't solve the ephemeral value case, but as demonstrated by the test cases, it does handle other cases.

I'm going to respond on D97092 <https://reviews.llvm.org/D97092> with a bit more context.  We could view this change as splitting out part of the functionality from D97092 <https://reviews.llvm.org/D97092>, or as a step towards a possible alternate.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97099

Files:
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/test/Analysis/ScalarEvolution/ranges.ll


Index: llvm/test/Analysis/ScalarEvolution/ranges.ll
===================================================================
--- llvm/test/Analysis/ScalarEvolution/ranges.ll
+++ llvm/test/Analysis/ScalarEvolution/ranges.ll
@@ -43,7 +43,7 @@
 ; CHECK-LABEL: 'shl'
 ; CHECK-NEXT:  Classifying expressions for: @shl
 ; CHECK-NEXT:    %res = shl i32 %a, 2
-; CHECK-NEXT:    --> (4 * %a) U: [0,-3) S: [-2147483648,2147483645)
+; CHECK-NEXT:    --> (4 * %a)<nuw><nsw> U: [0,4093) S: [0,4093)
 ; CHECK-NEXT:  Determining loop execution counts for: @shl
 ;
   %res = shl i32 %a, 2
@@ -56,7 +56,7 @@
 ; CHECK-LABEL: 'lshr'
 ; CHECK-NEXT:  Classifying expressions for: @lshr
 ; CHECK-NEXT:    %res = lshr i32 %a, 31
-; CHECK-NEXT:    --> (%a /u -2147483648) U: [0,2) S: [0,2)
+; CHECK-NEXT:    --> (%a /u -2147483648) U: [0,1) S: [0,1)
 ; CHECK-NEXT:  Determining loop execution counts for: @lshr
 ;
   %res = lshr i32 %a, 31
@@ -70,7 +70,7 @@
 ; CHECK-LABEL: 'udiv'
 ; CHECK-NEXT:  Classifying expressions for: @udiv
 ; CHECK-NEXT:    %res = udiv i32 %a, -2147483648
-; CHECK-NEXT:    --> (%a /u -2147483648) U: [0,2) S: [0,2)
+; CHECK-NEXT:    --> (%a /u -2147483648) U: [0,1) S: [0,1)
 ; CHECK-NEXT:  Determining loop execution counts for: @udiv
 ;
   %res = udiv i32 %a, 2147483648
@@ -83,7 +83,7 @@
 ; CHECK-LABEL: 'sext'
 ; CHECK-NEXT:  Classifying expressions for: @sext
 ; CHECK-NEXT:    %res = sext i8 %a to i64
-; CHECK-NEXT:    --> (sext i8 %a to i64) U: [-128,128) S: [-128,128)
+; CHECK-NEXT:    --> (zext i8 %a to i64) U: [0,128) S: [0,128)
 ; CHECK-NEXT:  Determining loop execution counts for: @sext
 ;
   %res = sext i8 %a to i64
@@ -96,7 +96,7 @@
 ; CHECK-LABEL: 'zext'
 ; CHECK-NEXT:  Classifying expressions for: @zext
 ; CHECK-NEXT:    %res = zext i8 %a to i64
-; CHECK-NEXT:    --> (zext i8 %a to i64) U: [0,256) S: [0,256)
+; CHECK-NEXT:    --> (zext i8 %a to i64) U: [0,128) S: [0,128)
 ; CHECK-NEXT:  Determining loop execution counts for: @zext
 ;
   %res = zext i8 %a to i64
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -158,6 +158,11 @@
   if (CxtI && CxtI->getParent())
     return CxtI;
 
+  // For an argument, we can use the start of the function.
+  if (auto *A = dyn_cast<Argument>(V))
+    if (A->getParent() && !A->getParent()->empty())
+      return CxtI = &*(A->getParent()->getEntryBlock().begin());
+
   return nullptr;
 }
 
@@ -176,6 +181,15 @@
   if (CxtI && CxtI->getParent())
     return CxtI;
 
+  // For an argument, we can use the start of the function.
+  if (auto *A = dyn_cast<Argument>(V1))
+    if (A->getParent() && !A->getParent()->empty())
+      return CxtI = &*(A->getParent()->getEntryBlock().begin());
+
+  if (auto *A = dyn_cast<Argument>(V2))
+    if (A->getParent() && !A->getParent()->empty())
+      return CxtI = &*(A->getParent()->getEntryBlock().begin());
+
   return nullptr;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97099.325112.patch
Type: text/x-patch
Size: 2983 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210220/d11a8822/attachment.bin>


More information about the llvm-commits mailing list