Skip to content

Commit

Permalink
[IPSCCP] Don't require noundef for !range annotation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nikic committed Mar 9, 2023
1 parent 7ed77da commit 6b545db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
7 changes: 0 additions & 7 deletions llvm/lib/Transforms/IPO/SCCP.cpp
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions llvm/test/Transforms/SCCP/ip-add-range-to-call.ll
Expand Up @@ -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:%.*]]
;
Expand Down Expand Up @@ -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:%.*]]
;
Expand All @@ -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
Expand Down Expand Up @@ -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:%.*]]
Expand Down Expand Up @@ -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:%.*]]
Expand Down

0 comments on commit 6b545db

Please sign in to comment.