Skip to content

Commit 635e8bd

Browse files
committed
[InstCombine] Add handling for (or (zext x), (shl (zext (ashr x, bw-1))), bw) -> (sext x) fold
Minor tweak llvm#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 llvm#76524
1 parent 445c43d commit 635e8bd

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,13 +3122,12 @@ static Value *matchOrConcat(Instruction &Or, InstCombiner::BuilderTy &Builder) {
31223122
// iX ext split: extending or(zext(x),shl(zext(y),bw/2) pattern
31233123
// to consume sext/ashr: or(zext(sext(x)),shl(zext(sext(ashr(x))),bw/2)
31243124
Value *X;
3125-
if (match(LowerSrc, m_SExt(m_Value(X))) &&
3125+
if (match(LowerSrc, m_SExtOrSelf(m_Value(X))) &&
31263126
match(UpperSrc,
3127-
m_SExt(m_AShr(
3127+
m_SExtOrSelf(m_AShr(
31283128
m_Specific(X),
3129-
m_SpecificInt(X->getType()->getScalarSizeInBits() - 1))))) {
3129+
m_SpecificInt(X->getType()->getScalarSizeInBits() - 1)))))
31303130
return Builder.CreateSExt(X, Ty);
3131-
}
31323131

31333132
return nullptr;
31343133
}

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)