From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2778EEACE for ; Sun, 19 Jan 2025 09:09:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737277780; cv=none; b=PffcGryOiBqdaX1/aSg4dW4g+djFsmBoYrUz9HQ5kpDgp9qU+fy2OpM3u0IAnPXcaCD0MnOMhcfkwXvTEFPN6/E+daXLb+m8tQl69hfCbDXNrE6XNaCrvHZMAT4bW/rcIBYD4yJMUJ9JRJj+A2ZMG0BIXG1S9FhY/fF7IIHKkyQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737277780; c=relaxed/simple; bh=BBzUd/CldbluvhzA6FJD/UySdY3ZfsER6b4j3NUUTm4=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EXWXaOQRzaOW4Fb0YGMtk0al0C3TIXlyjtz/pNQL6KH2djJj6rMPV6wF/hONX7XNomRGf+FTEL+uWR9DTPsW02fAk6yr32TGGfDfkhphuEDbjCcUn6L1Z8syuecr15n5BtCeNTFNV82n/XrcLs32kmDQMkGCeT8tAs1Cojm72a8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Nx7v9RiF; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Nx7v9RiF" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4368a293339so39308125e9.3 for ; Sun, 19 Jan 2025 01:09:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737277777; x=1737882577; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=GpRQfPo+dIVvMcJc83bhcvAD0N42aVYCbsSTsOGPCsU=; b=Nx7v9RiFE10GaWf+OeRdXb0hQLZ1c+Hm04MPSiOOisjfGrUmZmO1/BxVKGPoSV9zv4 jc4EvAIVATQJESaqPkxUbkhceNvyMbhBjN5qhrrjKHIKCONub7P89bLINothbx1G4sND U03ou3gz9zWgRr+IkVqfXyC+R1RC/IG10rPBCj4nCzW8BDkzLAZd8hFoNesMPTv80Jnz 6/ntPJhl0cq9AgU0EonVKC+piumfHhULmwb8mYig5hutAKy+orBxFuBvxKu1bqYC7+7P HBhHvX3qarEn9Dcoc55eJGA4ATTDpP0G3nLD1Opx9n1ssOpiGXwTGQXflt78HP9UHrxF z9/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737277777; x=1737882577; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GpRQfPo+dIVvMcJc83bhcvAD0N42aVYCbsSTsOGPCsU=; b=h4HE4zMyoG9SldMIh5CWq1msKmKbowQPO2NzyV+wDb9R67lqPp22Xv/Dx3CpUFfka4 Zg2QaKR3J3pH1g4DqdktJh1AC3s9QZmiBgybOvBToMaSfG7viFPfgztTTv3Yy0HeP8/N sjOo93/jM5FYDyH3f+nIycBiJ2CIX6lK7fHdz80BV4rAYqVHYjXjOxRov3bfg6dhrWp/ cac7UmT/xu8uebjqjw0SUzcgPHcxh2DcoVnpKVgqrj1/vNXqdrCt4bngzQYUyjZujxIr heSV4Th9x3eLaa4WWHVzfwvjI77PQl1fVcGlG2Fo6LDJaka+HYpeA5aY+sdYwxVXo9nJ jXaA== X-Forwarded-Encrypted: i=1; AJvYcCWyIx/q7FtmkW4RMUp5wNEIaXvswUC4PjCK2jDZj894BwFt61pal1Dd2PpFqejxa+19u4w6V8zl9/mEnXk=@vger.kernel.org X-Gm-Message-State: AOJu0Yxd36dPoE/30PYn+vFqIIMoOib5ATjtznHi/NECSoOCEE9hPvWe KLY9D8SLiKIUJg9hBswWhncCQ1hwu8EjtzHnw11/IX0K77rU4L55 X-Gm-Gg: ASbGncsIaXAQNu7CJaGzx9ybCjD8QdzHo/sZHAFhgFE7POYYyJUimm/nr0btaHWbQ+1 hXPJ2NCjt+KoQIyjmUU4pnhHXjfaaDNya+SwQLaKQlVhCKzDzVyehLcbc8gRrmbt7V/4/P25ETv Lr1uVqy3JjBlV1GDzL7TKId++PtG+5dGk0K9rzeKbhE7SZzyPasLtQfwilknyBweoU5n3M0TBOB 8TeKF4Rcno9SSrPDBQavTvCQq+yZSIoJxJShz02WHItX7lrpuIk2ea40cUMJSFeCRjfqk3Mk6r6 KA28MEJqP8Z5Wd/piM0QMAVA2a29Mack X-Google-Smtp-Source: AGHT+IEuKIzgPC9hm5HdrQMLOvk5XY5pw6JdVTD0sbRLPHCvA9Cnqc+BT5boheqzFsu1pqtmM2wImg== X-Received: by 2002:a05:600c:3b02:b0:434:a781:f5d5 with SMTP id 5b1f17b1804b1-4389143ba53mr84319045e9.30.1737277777068; Sun, 19 Jan 2025 01:09:37 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-437c75298adsm156216465e9.30.2025.01.19.01.09.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 01:09:36 -0800 (PST) Date: Sun, 19 Jan 2025 09:09:35 +0000 From: David Laight To: Guenter Roeck Cc: Linus Torvalds , David Laight , Arnd Bergmann , "linux-kernel@vger.kernel.org" , Jens Axboe , Matthew Wilcox , Christoph Hellwig , Andrew Morton , Andy Shevchenko , Dan Carpenter , "Jason A . Donenfeld" , "pedro.falcato@gmail.com" , Mateusz Guzik , "linux-mm@kvack.org" , Lorenzo Stoakes , intel-xe@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, David Airlie , Simona Vetter , Jani Nikula , Rodrigo Vivi Subject: Re: Buiild error in i915/xe Message-ID: <20250119090935.7c690f85@pumpkin> In-Reply-To: References: <34d53778977747f19cce2abb287bb3e6@AcuMS.aculab.com> <20250118170959.3aa56f4d@pumpkin> <29ef57a1-e4dd-4d5d-8726-f1f79c698b66@roeck-us.net> <20250118221123.5bb65e64@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 18 Jan 2025 14:58:48 -0800 Guenter Roeck wrote: > On 1/18/25 14:11, David Laight wrote: > > On Sat, 18 Jan 2025 13:21:39 -0800 > > Linus Torvalds wrote: > > > >> On Sat, 18 Jan 2025 at 09:49, Guenter Roeck wrote: > >>> > >>> No idea why the compiler would know that the values are invalid. > >> > >> It's not that the compiler knows tat they are invalid, but I bet what > >> happens is in scale() (and possibly other places that do similar > >> checks), which does this: > >> > >> WARN_ON(source_min > source_max); > >> ... > >> source_val = clamp(source_val, source_min, source_max); > >> > >> and the compiler notices that the ordering comparison in the first > >> WARN_ON() is the same as the one in clamp(), so it basically converts > >> the logic to > >> > >> if (source_min > source_max) { > >> WARN(..); > >> /* Do the clamp() knowing that source_min > source_max */ > >> source_val = clamp(source_val, source_min, source_max); > >> } else { > >> /* Do the clamp knowing that source_min <= source_max */ > >> source_val = clamp(source_val, source_min, source_max); > >> } > >> > >> (obviously I dropped the other WARN_ON in the conversion, it wasn't > >> relevant for this case). > >> > >> And now that first clamp() case is done with source_min > source_max, > >> and it triggers that build error because that's invalid. > >> > >> So the condition is not statically true in the *source* code, but in > >> the "I have moved code around to combine tests" case it now *is* > >> statically true as far as the compiler is concerned. > > > > Well spotted :-) > > > > One option would be to move the WARN_ON() below the clamp() and > > add an OPTIMISER_HIDE_VAR(source_max) between them. > > > > Or do something more sensible than the WARN(). > > Perhaps return target_min on any such errors? > > > > This helps: > > - WARN_ON(source_min > source_max); > - WARN_ON(target_min > target_max); > - > /* defensive */ > source_val = clamp(source_val, source_min, source_max); > > + WARN_ON(source_min > source_max); > + WARN_ON(target_min > target_max); That is a 'quick fix' ... Much better would be to replace the WARN() with (say): if (target_min >= target_max) return target_min; if (source_min >= source_max) return target_min + (target_max - target_min)/2; So that the return values are actually in range (in as much as one is defined). Note that the >= cpmparisons also remove a divide by zero. David > > Guenter >