https://github.com/danbrown-amd created https://github.com/llvm/llvm-project/pull/221105
Fixes #140824 Assisted-by: Claude Sonnet 4 >From abd49a074cd5d0dc820a401ecfbcacb8834433f4 Mon Sep 17 00:00:00 2001 From: danbrown-amd <[email protected]> Date: Thu, 3 Sep 2026 18:46:23 -0600 Subject: [PATCH] Use icmp-ne instead of truncation on boolean load Fixes #140824 Assisted-by: Claude Sonnet 4 --- clang/lib/Frontend/CompilerInvocation.cpp | 6 ++++++ clang/test/CodeGenHLSL/strict-bool.hlsl | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index ea8368908879a..fb2293bc0e157 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -653,6 +653,12 @@ static bool FixupInvocation(CompilerInvocation &Invocation, Warnings.insert(Warnings.begin(), "vector-conversion"); if (!llvm::is_contained(Warnings, "matrix-conversion")) Warnings.insert(Warnings.begin(), "matrix-conversion"); + + // HLSL booleans in memory are i32; any non-zero value is true. + // Use icmp-ne rather than truncation to avoid InstCombine rewriting + // trunc i32 to i1 into an illegal wide <N x i1> bitcast (issue #140824). + if (!Args.hasArg(OPT_load_bool_from_mem)) + CodeGenOpts.setLoadBoolFromMem(CodeGenOptions::BoolFromMem::NonZero); } // When these options are used, the compiler is allowed to apply diff --git a/clang/test/CodeGenHLSL/strict-bool.hlsl b/clang/test/CodeGenHLSL/strict-bool.hlsl index 31867065e77a3..30bdc02231fa5 100644 --- a/clang/test/CodeGenHLSL/strict-bool.hlsl +++ b/clang/test/CodeGenHLSL/strict-bool.hlsl @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -O1 -load-bool-from-mem=truncate -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK-TRUNCATE // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -O1 -load-bool-from-mem=nonzero -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK-NONZERO -// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -O0 -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK-NONZERO +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -O1 -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK-NONZERO typedef bool bool8_t __attribute__((ext_vector_type(8))); extern bool8_t vec; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
