<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/90211>90211</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Miscomplilation after GVN changes in 84bcfa0e1b
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          kasper93
      </td>
    </tr>
</table>

<pre>
    Hi,

I got some crashes with valid looking code, execution goes into `int3` as if there were some UB, but it shouldn't. I minimized the case as much as I could given that it was not easy to keep creduce from not introducing other issues. 

I've bisected the miscalculation to 84bcfa0e1b34938d1d11a44e9e17c6e222dd2f42 /CC @weiguozhi 

I think at some point I had a test which were breaking with `x86-64-v2` too, but let's stick with this guy.
```
clang -x c -O2 -march=x86-64-v4 -o bad.s -S test.c
```

``` C
struct rect
{
    float x0, x1;
    float y0, y1;
};

float roundf(float);
void bar(struct rect *);

int i0, i1, i2, i3, i4, i5, i6, i7, i8, i10, i11, i12, i13;

void foo()
{
    if (i1)
 {
        struct rect rc = {0};
        bar(&rc);

        rc.x0 = rc.x0 < 0 ? 0 : (rc.x0 > i7 ? i7 : rc.x0);
        rc.x1 = rc.x1 < 0 ? 0 : (rc.x1 > i8 ? i8 : rc.x1);
        rc.y0 = rc.y0 < 0 ? 0 : (rc.y0 > i7 ? i7 : rc.y0);
        rc.y1 = rc.y1 < 0 ? 0 : (rc.y1 > i8 ? i8 : rc.y1);

        if (i0)
            bar(&rc);

        i6 = roundf(rc.x0);
        i5 = roundf(rc.y0);
        i4 = roundf(rc.x1);
        i3 = roundf(rc.y1);
    }

    if (i2)
 {
        int tmp = i6;
        i6 = i4;
        i4 = tmp;

        tmp = i5;
        i5 = i3;
        i3 = tmp;
 }

    struct rect rc1 = {
        (i6 - i12) * i10,
        (i4 - i13) * i11,
        (i5 - i12) * i10,
        (i3 - i13) * i11
 };

    bar(&rc1);
}
```

Looks like it doesn't like when `i1` is non-zero, but I don't see anything in the code that would explain that. It goes into `i1` branch and bails our first `bar` call, while it should call it 1 or 2 times more. On Windows it inserts `int3` on top of that.
``` S
foo:                                    # @foo
.seh_proc foo
# %bb.0:
        subq    $56, %rsp
        .seh_stackalloc 56
        .seh_endprologue
        cmpl    $0, i1(%rip)
        jne     .LBB0_3
...
.LBB0_3:
        vxorps  %xmm0, %xmm0, %xmm0
        vmovaps %xmm0, 32(%rsp)
        leaq    32(%rsp), %rcx
        callq   bar
        int3
        .seh_endproc
```

Before the patch 84bcfa0e1b34938d1d11a44e9e17c6e222dd2f42 there is no issue.

Thanks,
Kacper
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMV0mT46gS_jX4kmEFQrJsHXyo5dV7Fa9n-tCzHDsQSlu0EWgAeelfPwGS93JHOSrSsvLj48tkySzunFxrxCWZPZPZ64T3vjF2ueGuQ1tmk8rUh-X_JGEvhL4S-jTYd1gbD860CMJy16CDnfQNbLmSNShjNlKvQZgaCXsB3KPovTQa1gYdSO0NkIJK7TNSUOAO5Ap8gxZhF0zk_fM5DK16D9KDa0yvak3Y3CfwDq3UspU_sQ6jQHCHgaTtRRO-30EENKzlFjX4hkeKHXegjQfk7gDewAaxA2Gx7gXCypo2eqX21tS9CPJNkATSuR5dAlfhEzbfIlTSofCjilY6wZXoFY-RegOLvBIrTjGtsrzMFnVapynPcywxnYsCGWN1zVY5A8LeXl6A5HSHct2bn428ng18I_UG-Jjxzkjt4R0aXgMHj87DrpGiGZJXWeQx-3FBSEH3i2Ja5NMtC7n2xhzTqtATNnfgvBSbAe0b6WDdH5Jx-oKOf_GnUFyvYboHAdOvDKYtt6Ih2etxghymBipeJw6m36KuRHxIdPMSxq3lvO2FB4vCj4j58_AAALBShnvY0yB_n5LsznWIrsPZReav5-doB6A1va5XhC3iT8LKE2prZA0Vt4QtLsQAYU-XqMGGNZBxSplGy6LNos2jnUVbRDuPdjHgx2HDuH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