Skip to content

Commit 1db716a

Browse files
committed
fix lower int_to_bool cast
1 parent 8a8ba9e commit 1db716a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,16 @@ class CIRBrCondOpLowering
612612
mlir::ConversionPatternRewriter &rewriter) const override {
613613
mlir::Value i1Condition;
614614

615+
auto hasOneUse = false;
616+
if (auto defOp = brOp.getCond().getDefiningOp())
617+
if (defOp->getResult(0).hasOneUse())
618+
hasOneUse = true;
619+
615620
if (auto defOp = adaptor.getCond().getDefiningOp()) {
616621
if (auto zext = dyn_cast<mlir::LLVM::ZExtOp>(defOp)) {
617622
if (zext->use_empty() &&
618-
zext->getOperand(0).getType() == rewriter.getI1Type()) {
623+
zext->getOperand(0).getType() == rewriter.getI1Type() &&
624+
hasOneUse) {
619625
i1Condition = zext->getOperand(0);
620626
rewriter.eraseOp(zext);
621627
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -fclangir-mem2reg -emit-llvm %s -o %t.ll
2+
3+
#include <stdbool.h>
4+
5+
bool test() {
6+
bool x = false;
7+
if (x) {
8+
bool u = x;
9+
return u;
10+
}
11+
return x;
12+
}

0 commit comments

Comments
 (0)