Index: lib/Transforms/Scalar/StructurizeCFG.cpp =================================================================== --- lib/Transforms/Scalar/StructurizeCFG.cpp +++ lib/Transforms/Scalar/StructurizeCFG.cpp @@ -375,12 +375,14 @@ /// \brief Invert the given condition Value *StructurizeCFG::invert(Value *Condition) { + Value *A; + // First: Check if it's a constant if (Constant *C = dyn_cast(Condition)) return ConstantExpr::getNot(C); // Second: If the condition is already inverted, return the original value - if (match(Condition, m_Not(m_Value(Condition)))) + if (match(Condition, m_Not(m_Value(A)))) return Condition; if (Instruction *Inst = dyn_cast(Condition)) { Index: test/Transforms/StructurizeCFG/invert-condition.ll =================================================================== --- /dev/null +++ test/Transforms/StructurizeCFG/invert-condition.ll @@ -0,0 +1,17 @@ +; RUN: opt -S -structurizecfg %s | FileCheck %s + +; CHECK: %0 = xor i1 %tmp4, true +define void @invert_condition(i1 %arg) { +bb: + %tmp = load volatile float, float addrspace(1)* undef + %tmp1 = load volatile float, float addrspace(1)* undef + br label %bb2 + +bb2: ; preds = %bb2, %bb + %tmp3 = fcmp oge float %tmp, %tmp1 + %tmp4 = xor i1 %arg, %tmp3 + br i1 %tmp4, label %bb2, label %bb5 + +bb5: ; preds = %bb2 + ret void +}