[llvm] 5163319 - [InstCombine] Use `ConstantInt::getBool` instead of `Constant::getIntegerValue`. NFC.

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 16 02:42:40 PDT 2023


Author: Yingwei Zheng
Date: 2023-09-16T17:41:10+08:00
New Revision: 5163319ee2a048407f83de3ff9ab00613939371a

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

LOG: [InstCombine] Use `ConstantInt::getBool` instead of `Constant::getIntegerValue`. NFC.

See also https://reviews.llvm.org/D156238#inline-1546774

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 56a542479a24d5a..a219dac7acfbe16 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -5054,14 +5054,10 @@ InstCombinerImpl::foldICmpWithMinMaxImpl(Instruction &I,
   case ICmpInst::ICMP_UGT:
   case ICmpInst::ICMP_SGE:
   case ICmpInst::ICMP_UGE: {
-    auto FoldIntoConstant = [&](bool Value) {
-      return replaceInstUsesWith(
-          I, Constant::getIntegerValue(
-                 I.getType(), APInt(1U, static_cast<uint64_t>(Value))));
-    };
     auto FoldIntoCmpYZ = [&]() -> Instruction * {
       if (CmpYZ.has_value())
-        return FoldIntoConstant(*CmpYZ);
+        return replaceInstUsesWith(I,
+                                   ConstantInt::getBool(I.getType(), *CmpYZ));
       return ICmpInst::Create(Instruction::ICmp, Pred, Y, Z);
     };
 
@@ -5073,7 +5069,7 @@ InstCombinerImpl::foldICmpWithMinMaxImpl(Instruction &I,
         // min(X, Y) <= Z   X <= Z  true
         // max(X, Y) > Z    X > Z   true
         // max(X, Y) >= Z   X >= Z  true
-        return FoldIntoConstant(true);
+        return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType()));
       } else {
         //      Expr        Fact    Result
         // max(X, Y) < Z    X < Z   Y < Z
@@ -5096,7 +5092,7 @@ InstCombinerImpl::foldICmpWithMinMaxImpl(Instruction &I,
         // max(X, Y) <= Z   X > Z   false
         // min(X, Y) > Z    X <= Z  false
         // min(X, Y) >= Z   X < Z   false
-        return FoldIntoConstant(false);
+        return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType()));
       }
     }
     break;


        


More information about the llvm-commits mailing list