[llvm-branch-commits] [llvm] 0777364 - [InstCombine] Refactor foldICmpMulConstant

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 23 10:10:58 PDT 2022


Author: Alexander Shaposhnikov
Date: 2022-08-23T19:09:48+02:00
New Revision: 077736456fd231aa7e2555abff58b42972bfc043

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

LOG: [InstCombine] Refactor foldICmpMulConstant

This is a follow-up to 2ebfda2417
(replace "if" with "else if" since the cases nuw/nsw
were meant to be handled separately).

Test plan:
1/ ninja check-llvm check-clang check-lld
2/ Bootstrapped LLVM/Clang pass tests

(cherry picked from commit d982f1e0c69f3447c4520ae4c010520f62ed1174)

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/test/Transforms/InstCombine/icmp-mul.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 158d2e8289e0b..edbd4091d1d2a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2040,9 +2040,7 @@ Instruction *InstCombinerImpl::foldICmpMulConstant(ICmpInst &Cmp,
       NewC = ConstantInt::get(
           Mul->getType(),
           APIntOps::RoundingSDiv(C, *MulC, APInt::Rounding::DOWN));
-  }
-
-  if (Mul->hasNoUnsignedWrap()) {
+  } else if (Mul->hasNoUnsignedWrap()) {
     if (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_UGE)
       NewC = ConstantInt::get(
           Mul->getType(),

diff  --git a/llvm/test/Transforms/InstCombine/icmp-mul.ll b/llvm/test/Transforms/InstCombine/icmp-mul.ll
index e07e2d05136a1..65a7fccc8872b 100644
--- a/llvm/test/Transforms/InstCombine/icmp-mul.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-mul.ll
@@ -860,7 +860,9 @@ define i1 @splat_mul_known_lz(i32 %x) {
 
 define i1 @splat_mul_unknown_lz(i32 %x) {
 ; CHECK-LABEL: @splat_mul_unknown_lz(
-; CHECK-NEXT:    [[R:%.*]] = icmp sgt i32 [[X:%.*]], -1
+; CHECK-NEXT:    [[Z:%.*]] = zext i32 [[X:%.*]] to i128
+; CHECK-NEXT:    [[M:%.*]] = mul nuw nsw i128 [[Z]], 18446744078004518913
+; CHECK-NEXT:    [[R:%.*]] = icmp ult i128 [[M]], 39614081257132168796771975168
 ; CHECK-NEXT:    ret i1 [[R]]
 ;
   %z = zext i32 %x to i128


        


More information about the llvm-branch-commits mailing list