[llvm] 6b545db - [IPSCCP] Don't require noundef for !range annotation

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 9 01:25:48 PST 2023


Author: Nikita Popov
Date: 2023-03-09T10:25:04+01:00
New Revision: 6b545db83c5a4e2c79e0b289e840be2c5fbbf327

URL: https://github.com/llvm/llvm-project/commit/6b545db83c5a4e2c79e0b289e840be2c5fbbf327
DIFF: https://github.com/llvm/llvm-project/commit/6b545db83c5a4e2c79e0b289e840be2c5fbbf327.diff

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

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, restoring
it to its original version (which is now valid).

Differential Revision: https://reviews.llvm.org/D144467

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/SCCP.cpp b/llvm/lib/Transforms/IPO/SCCP.cpp
index c736c298c7dae..46a66989c0916 100644
--- a/llvm/lib/Transforms/IPO/SCCP.cpp
+++ b/llvm/lib/Transforms/IPO/SCCP.cpp
@@ -292,13 +292,6 @@ static bool runIPSCCP(
         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.

diff  --git a/llvm/test/Transforms/SCCP/ip-add-range-to-call.ll b/llvm/test/Transforms/SCCP/ip-add-range-to-call.ll
index cc5c93fa4d4c9..825e44a81860f 100644
--- a/llvm/test/Transforms/SCCP/ip-add-range-to-call.ll
+++ b/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 @@ define i32 @caller2(i32 %x) {
 
 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 @@ define void @caller_cb1() {
 
 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 @@ define void @caller_cb2() {
 
 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 @@ define void @caller_cb3() {
 ; 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:%.*]]


        


More information about the llvm-commits mailing list