[llvm] 5d28678 - [InstCombine] Fix incorrect zero ext in select of lshr/ashr fold
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 16 06:02:28 PDT 2024
Author: Nikita Popov
Date: 2024-08-16T15:02:16+02:00
New Revision: 5d28678277195e0b136198323ef4afa4561f8796
URL: https://github.com/llvm/llvm-project/commit/5d28678277195e0b136198323ef4afa4561f8796
DIFF: https://github.com/llvm/llvm-project/commit/5d28678277195e0b136198323ef4afa4561f8796.diff
LOG: [InstCombine] Fix incorrect zero ext in select of lshr/ashr fold
The -1 constant should be sign extended, not zero extended.
Split out from https://github.com/llvm/llvm-project/pull/80309.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/ashr-lshr.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index b86f27168303a..b8b77bec1b900 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -679,11 +679,11 @@ static Value *foldSelectICmpLshrAshr(const ICmpInst *IC, Value *TrueVal,
Value *X, *Y;
unsigned Bitwidth = CmpRHS->getType()->getScalarSizeInBits();
if ((Pred != ICmpInst::ICMP_SGT ||
- !match(CmpRHS,
- m_SpecificInt_ICMP(ICmpInst::ICMP_SGE, APInt(Bitwidth, -1)))) &&
+ !match(CmpRHS, m_SpecificInt_ICMP(ICmpInst::ICMP_SGE,
+ APInt::getAllOnes(Bitwidth)))) &&
(Pred != ICmpInst::ICMP_SLT ||
- !match(CmpRHS,
- m_SpecificInt_ICMP(ICmpInst::ICMP_SGE, APInt(Bitwidth, 0)))))
+ !match(CmpRHS, m_SpecificInt_ICMP(ICmpInst::ICMP_SGE,
+ APInt::getZero(Bitwidth)))))
return nullptr;
// Canonicalize so that ashr is in FalseVal.
diff --git a/llvm/test/Transforms/InstCombine/ashr-lshr.ll b/llvm/test/Transforms/InstCombine/ashr-lshr.ll
index 4a3f836e95c3c..a81cd47b1cd4b 100644
--- a/llvm/test/Transforms/InstCombine/ashr-lshr.ll
+++ b/llvm/test/Transforms/InstCombine/ashr-lshr.ll
@@ -63,11 +63,8 @@ define i32 @ashr_lshr2(i32 %x, i32 %y) {
define i128 @ashr_lshr2_i128(i128 %x, i128 %y) {
; CHECK-LABEL: @ashr_lshr2_i128(
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i128 [[X:%.*]], 5
-; CHECK-NEXT: [[L:%.*]] = lshr i128 [[X]], [[Y:%.*]]
-; CHECK-NEXT: [[R:%.*]] = ashr exact i128 [[X]], [[Y]]
-; CHECK-NEXT: [[RET:%.*]] = select i1 [[CMP]], i128 [[L]], i128 [[R]]
-; CHECK-NEXT: ret i128 [[RET]]
+; CHECK-NEXT: [[CMP1:%.*]] = ashr i128 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: ret i128 [[CMP1]]
;
%cmp = icmp sgt i128 %x, 5
%l = lshr i128 %x, %y
More information about the llvm-commits
mailing list