[llvm] [X86] Fix a>b being different than b<a on -mattr=+avx2 (PR #195712)

via llvm-commits llvm-commits at lists.llvm.org
Mon May 4 13:54:54 PDT 2026


================
@@ -25060,6 +25060,13 @@ static SDValue LowerVSETCC(SDValue Op, const X86Subtarget &Subtarget,
   if (ISD::isUnsignedIntSetCC(Cond) &&
       (FlipSigns || ISD::isTrueWhenEqual(Cond)) &&
       TLI.isOperationLegal(ISD::UMIN, VT)) {
+    // If Op0 is a load and Op1 is not, swap them to allow folding the load
+    // into the min/max operation.
+    if (Op0.getOpcode() == ISD::LOAD && Op1.getOpcode() != ISD::LOAD) {
----------------
thatSteveFan wrote:

Changed to use X86::mayFoldLoad, and added a test. Used an AI to try and get the llvm-ir, based on the following code, but I wasn't sure what exactly needs to be checked in the test. Test is probably over-specified.

struct Values {
    uint32_t vals[8];
};
int test_multiuse(Values& v1, Values& v2, uint32_t* external_dest) {
    int count = 0;
    for (int i = 0; i < 8; ++i) {
         uint32_t a = v1.vals[i];
         uint32_t b = v2.vals[i];
         count += (a < b);
         if (a == 42) {
             *external_dest = a; 
         }
      }
      return count;
}


https://github.com/llvm/llvm-project/pull/195712


More information about the llvm-commits mailing list