During the SeparateConstOffsetFromGEP pass, a - b and b - a will be
considered equivalent in some instances.
An example- the IR contains:
BB1: %add = add %a, 511 br label %BB2 BB2: %sub2 = sub %b, %a br label %BB3 BB3: %sub1 = sub %add, %b %gep = getelementptr float, ptr %p, %sub1
Step 1 in the SeparateConstOffsetFromGEP pass, after split constant index:
BB1: %add = add %a, 511 br label %BB2 BB2: %sub2 = sub %b, %a br label %BB3 BB3: %sub.t = sub %a, %b %gep.base = getelementptr float, ptr %p, %sub.t %gep = getelementptr float, ptr %gep.base, 511
Step 2, after reuniteExts:
BB1: br label %BB2 BB2: %sub2 = sub %b, %a br label %BB3 BB3: %gep.base = getelementptr float, ptr %p, %sub2 %gep = getelementptr float, ptr %gep.base, 511
Obviously, reuniteExts treated a - b and b - a as equivalent.
This patch fixes that.
It would be better to use a RUN line with opt like existing tests in this and the parent directory.
IIUC, we have a miscompile, so you can create a baseline test that shows the bug, commit that to main, and then regenerate the CHECK lines with this patch, so we show the difference in IR. Please use "utils/update_test_checks.py" to auto-generate the CHECK lines instead of manually writing them.