[llvm] ace0bf7 - [ValueTracking] Fix incorrect handling of canCreateUndefOrPoison

Juneyoung Lee via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 21 17:31:42 PDT 2020


Author: Juneyoung Lee
Date: 2020-07-22T09:31:16+09:00
New Revision: ace0bf749099c104ad50252988097c9495df7ccd

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

LOG: [ValueTracking] Fix incorrect handling of canCreateUndefOrPoison

.. in isGuaranteedNotToBeUndefOrPoison.

This caused early exit of isGuaranteedNotToBeUndefOrPoison, making it return
imprecise result.

Reviewed By: nikic

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

Added: 
    

Modified: 
    llvm/lib/Analysis/ValueTracking.cpp
    llvm/test/Transforms/InstSimplify/freeze.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index ed22718d866e..12abe3486cb3 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4824,10 +4824,7 @@ bool llvm::isGuaranteedNotToBeUndefOrPoison(const Value *V,
         return true;
     }
 
-    if (canCreateUndefOrPoison(Opr))
-      return false;
-
-    if (all_of(Opr->operands(), OpCheck))
+    if (!canCreateUndefOrPoison(Opr) && all_of(Opr->operands(), OpCheck))
       return true;
   }
 

diff  --git a/llvm/test/Transforms/InstSimplify/freeze.ll b/llvm/test/Transforms/InstSimplify/freeze.ll
index 8659687f07e7..3c4ca7a1afb9 100644
--- a/llvm/test/Transforms/InstSimplify/freeze.ll
+++ b/llvm/test/Transforms/InstSimplify/freeze.ll
@@ -381,6 +381,23 @@ EXIT:
   ret i32 %fr2
 }
 
+declare i32 @any_num()
+
+define i32 @brcond_call() {
+; CHECK-LABEL: @brcond_call(
+; CHECK-NEXT:    [[X:%.*]] = call i32 @any_num()
+; CHECK-NEXT:    switch i32 [[X]], label [[EXIT:%.*]] [
+; CHECK-NEXT:    ]
+; CHECK:       EXIT:
+; CHECK-NEXT:    ret i32 [[X]]
+;
+  %x = call i32 @any_num()
+  switch i32 %x, label %EXIT []
+EXIT:
+  %y = freeze i32 %x
+  ret i32 %y
+}
+
 define i1 @brcond_noopt(i1 %c, i1 %c2) {
 ; CHECK-LABEL: @brcond_noopt(
 ; CHECK-NEXT:    [[F:%.*]] = freeze i1 [[C:%.*]]


        


More information about the llvm-commits mailing list