Skip to content

Commit 60a88d4

Browse files
nikictru
authored andcommitted
[InstCombine] Fix select + cast fold with constant expression (PR64669)
The zext constant expression was detected by the fold, but then handled as a sext. Use ZExtOperator instead of ZExtInst to handle constant expressions. Fixes llvm#64669. (cherry picked from commit c15ccfb)
1 parent 1991da9 commit 60a88d4

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ InstCombinerImpl::foldBinOpOfSelectAndCastOfSelectCondition(BinaryOperator &I) {
906906

907907
auto NewFoldedConst = [&](bool IsTrueArm, Value *V) {
908908
bool IsCastOpRHS = (CastOp == RHS);
909-
bool IsZExt = isa<ZExtInst>(CastOp);
909+
bool IsZExt = isa<ZExtOperator>(CastOp);
910910
Constant *C;
911911

912912
if (IsTrueArm) {

llvm/test/Transforms/InstCombine/binop-select-cast-of-select-cond.ll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,19 @@ define <2 x i8> @vectorized_add(<2 x i1> %c, <2 x i8> %arg) {
224224
%add = add <2 x i8> %sel, %zext
225225
ret <2 x i8> %add
226226
}
227+
228+
@b = external global [72 x i32]
229+
@c = external global i32
230+
231+
define i64 @pr64669(i64 %a) {
232+
; CHECK-LABEL: define i64 @pr64669
233+
; CHECK-SAME: (i64 [[A:%.*]]) {
234+
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[A]], 1
235+
; CHECK-NEXT: [[ADD:%.*]] = select i1 icmp ne (ptr getelementptr inbounds ([72 x i32], ptr @b, i64 0, i64 25), ptr @c), i64 [[TMP1]], i64 0
236+
; CHECK-NEXT: ret i64 [[ADD]]
237+
;
238+
%mul = select i1 icmp ne (ptr getelementptr inbounds ([72 x i32], ptr @b, i64 0, i64 25), ptr @c), i64 %a, i64 0
239+
%conv3 = zext i1 icmp ne (ptr getelementptr inbounds ([72 x i32], ptr @b, i64 0, i64 25), ptr @c) to i64
240+
%add = add nsw i64 %mul, %conv3
241+
ret i64 %add
242+
}

0 commit comments

Comments
 (0)