Skip to content

Commit d84dc8f

Browse files
authored
[InstCombine] Add handling for (or (zext x), (shl (zext (ashr x, bw/2-1))), bw/2) -> (sext x) fold (#130316)
Minor tweak to #129363 which handled all the cases where there was a sext for the original source value, but not for cases where the source is already half the size of the destination type Another regression noticed in #76524
1 parent 6fbe491 commit d84dc8f

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,15 +3120,16 @@ static Value *matchOrConcat(Instruction &Or, InstCombiner::BuilderTy &Builder) {
31203120
return ConcatIntrinsicCalls(Intrinsic::bitreverse, UpperBRev, LowerBRev);
31213121

31223122
// iX ext split: extending or(zext(x),shl(zext(y),bw/2) pattern
3123-
// to consume sext/ashr: or(zext(sext(x)),shl(zext(sext(ashr(x))),bw/2)
3123+
// to consume sext/ashr:
3124+
// or(zext(sext(x)),shl(zext(sext(ashr(x,xbw-1))),bw/2)
3125+
// or(zext(x),shl(zext(ashr(x,xbw-1)),bw/2)
31243126
Value *X;
3125-
if (match(LowerSrc, m_SExt(m_Value(X))) &&
3127+
if (match(LowerSrc, m_SExtOrSelf(m_Value(X))) &&
31263128
match(UpperSrc,
3127-
m_SExt(m_AShr(
3129+
m_SExtOrSelf(m_AShr(
31283130
m_Specific(X),
3129-
m_SpecificInt(X->getType()->getScalarSizeInBits() - 1))))) {
3131+
m_SpecificInt(X->getType()->getScalarSizeInBits() - 1)))))
31303132
return Builder.CreateSExt(X, Ty);
3131-
}
31323133

31333134
return nullptr;
31343135
}

llvm/test/Transforms/InstCombine/iX-ext-split.ll

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ define void @i128_ext_split_store_i64(i64 %x, ptr %out) {
9494
; CHECK-LABEL: define void @i128_ext_split_store_i64(
9595
; CHECK-SAME: i64 [[X:%.*]], ptr [[OUT:%.*]]) {
9696
; CHECK-NEXT: [[ENTRY:.*:]]
97-
; CHECK-NEXT: [[LO:%.*]] = zext i64 [[X]] to i128
98-
; CHECK-NEXT: [[SIGN:%.*]] = ashr i64 [[X]], 63
99-
; CHECK-NEXT: [[WIDEN:%.*]] = zext i64 [[SIGN]] to i128
100-
; CHECK-NEXT: [[HI:%.*]] = shl nuw i128 [[WIDEN]], 64
101-
; CHECK-NEXT: [[RES:%.*]] = or disjoint i128 [[HI]], [[LO]]
97+
; CHECK-NEXT: [[RES:%.*]] = sext i64 [[X]] to i128
10298
; CHECK-NEXT: store i128 [[RES]], ptr [[OUT]], align 16
10399
; CHECK-NEXT: ret void
104100
;

0 commit comments

Comments
 (0)