[PATCH] D144467: [IPSCCP] Don't require noundef for !range annotation

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 21 03:03:38 PST 2023


nikic created this revision.
nikic added reviewers: fhahn, nlopes, efriedma.
Herald added subscribers: snehasish, ormris, StephenFan, hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Since https://reviews.llvm.org/D141386 `!range` violations return poison instead of causing immediate undefined behavior. As such, it is fine for IPSCCP to infer `!range` even if the value might be poison. (The value cannot be undef as this would promote undef to poison, but this is already checked separately.)

This basically undoes the late change done to D83952 <https://reviews.llvm.org/D83952>, restoring it to its original version (which is now valid).


https://reviews.llvm.org/D144467

Files:
  llvm/lib/Transforms/IPO/SCCP.cpp
  llvm/test/Transforms/SCCP/ip-add-range-to-call.ll


Index: llvm/test/Transforms/SCCP/ip-add-range-to-call.ll
===================================================================
--- llvm/test/Transforms/SCCP/ip-add-range-to-call.ll
+++ llvm/test/Transforms/SCCP/ip-add-range-to-call.ll
@@ -4,7 +4,7 @@
 ; Test 1.
 ; Both arguments and return value of @callee can be tracked. The inferred range
 ; can be added to call sites.
-define internal noundef i32 @callee(i32 %x) {
+define internal i32 @callee(i32 %x) {
 ; CHECK-LABEL: @callee(
 ; CHECK-NEXT:    ret i32 [[X:%.*]]
 ;
@@ -42,7 +42,7 @@
 
 declare void @use_cb1(ptr)
 
-define internal noundef i32 @callee2(i32 %x) {
+define internal i32 @callee2(i32 %x) {
 ; CHECK-LABEL: @callee2(
 ; CHECK-NEXT:    ret i32 [[X:%.*]]
 ;
@@ -69,7 +69,7 @@
 
 declare void @use_cb2(ptr)
 
-define internal noundef i32 @callee3(i32 %x) {
+define internal i32 @callee3(i32 %x) {
 ; CHECK-LABEL: @callee3(
 ; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[X:%.*]], 10
 ; CHECK-NEXT:    [[S:%.*]] = select i1 [[C]], i32 500, i32 600
@@ -99,7 +99,7 @@
 
 declare void @use_cb3(ptr)
 
-define internal noundef i32 @callee4(i32 %x, i32 %y) {
+define internal i32 @callee4(i32 %x, i32 %y) {
 ; CHECK-LABEL: @callee4(
 ; CHECK-NEXT:    [[C:%.*]] = icmp eq i32 [[X:%.*]], 10
 ; CHECK-NEXT:    [[S:%.*]] = select i1 [[C]], i32 500, i32 [[Y:%.*]]
@@ -128,7 +128,7 @@
 ; Test 5.
 ; Range for the return value of callee5 includes undef. No range metadata
 ; should be added at call sites.
-define internal noundef i32 @callee5(i32 %x, i32 %y) {
+define internal i32 @callee5(i32 %x, i32 %y) {
 ; CHECK-LABEL: @callee5(
 ; CHECK-NEXT:    [[C:%.*]] = icmp slt i32 [[X:%.*]], 15
 ; CHECK-NEXT:    br i1 [[C]], label [[BB1:%.*]], label [[BB2:%.*]]
Index: llvm/lib/Transforms/IPO/SCCP.cpp
===================================================================
--- llvm/lib/Transforms/IPO/SCCP.cpp
+++ llvm/lib/Transforms/IPO/SCCP.cpp
@@ -292,13 +292,6 @@
         if (!CB || CB->getCalledFunction() != F)
           continue;
 
-        // Limit to cases where the return value is guaranteed to be neither
-        // poison nor undef. Poison will be outside any range and currently
-        // values outside of the specified range cause immediate undefined
-        // behavior.
-        if (!isGuaranteedNotToBeUndefOrPoison(CB, nullptr, CB))
-          continue;
-
         // Do not touch existing metadata for now.
         // TODO: We should be able to take the intersection of the existing
         // metadata and the inferred range.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144467.499097.patch
Type: text/x-patch
Size: 2501 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230221/13a5fc32/attachment.bin>


More information about the llvm-commits mailing list