Commit c15ccfb2 authored by Nikita Popov's avatar Nikita Popov
Browse files

[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 https://github.com/llvm/llvm-project/issues/64669.
parent f44beecb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -908,7 +908,7 @@ InstCombinerImpl::foldBinOpOfSelectAndCastOfSelectCondition(BinaryOperator &I) {

  auto NewFoldedConst = [&](bool IsTrueArm, Value *V) {
    bool IsCastOpRHS = (CastOp == RHS);
    bool IsZExt = isa<ZExtInst>(CastOp);
    bool IsZExt = isa<ZExtOperator>(CastOp);
    Constant *C;

    if (IsTrueArm) {
+16 −0
Original line number Diff line number Diff line
@@ -224,3 +224,19 @@ define <2 x i8> @vectorized_add(<2 x i1> %c, <2 x i8> %arg) {
  %add = add <2 x i8> %sel, %zext
  ret <2 x i8> %add
}

@b = external global [72 x i32]
@c = external global i32

define i64 @pr64669(i64 %a) {
; CHECK-LABEL: define i64 @pr64669
; CHECK-SAME: (i64 [[A:%.*]]) {
; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[A]], 1
; 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
; CHECK-NEXT:    ret i64 [[ADD]]
;
  %mul = select i1 icmp ne (ptr getelementptr inbounds ([72 x i32], ptr @b, i64 0, i64 25), ptr @c), i64 %a, i64 0
  %conv3 = zext i1 icmp ne (ptr getelementptr inbounds ([72 x i32], ptr @b, i64 0, i64 25), ptr @c) to i64
  %add = add nsw i64 %mul, %conv3
  ret i64 %add
}